Skip to content

Commit e410842

Browse files
authored
chore: Reanimated hooks cleanup (#443)
## Description A little cleanup of reanimated hooks and improvement of the `useFrameCallback` to prevent re-subscription on renders.
1 parent f9c9875 commit e410842

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

packages/react-native-sortables/src/components/shared/SortableContainer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ type AnimatedHeightContainerProps = PropsWithChildren<
2121
DropIndicatorSettings & {
2222
dimensionsAnimationType: DimensionsAnimation;
2323
overflow: Overflow;
24-
onLayout: (width: number, height: number) => void;
2524
debug?: boolean;
2625
style?: StyleProp<ViewStyle>;
26+
onLayout: (width: number, height: number) => void;
2727
}
2828
>;
2929

@@ -76,7 +76,7 @@ export default function SortableContainer({
7676
animateWorklet
7777
)
7878
};
79-
}, [dimensionsAnimationType]);
79+
});
8080

8181
const innerContainerStyle = useAnimatedStyle(() => ({
8282
...(controlledContainerDimensions.height &&

packages/react-native-sortables/src/providers/shared/AutoScrollProvider/index.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ const { AutoScrollProvider, useAutoScrollContext } = createProvider(
6262
// SMOOTH SCROLL POSITION UPDATER
6363
// Updates the scroll position smoothly
6464
// (quickly at first, then slower if the remaining distance is small)
65-
const frameCallback = useFrameCallback(() => {
65+
const frameCallbackFunction = useCallback(() => {
66+
'worklet';
6667
const targetOffset = targetScrollOffset.value;
6768
if (!isFrameCallbackActive.value || targetOffset === null) {
6869
return;
@@ -96,7 +97,17 @@ const { AutoScrollProvider, useAutoScrollContext } = createProvider(
9697
scrollTo(scrollableRef, 0, nextOffset, false);
9798
}
9899
prevScrollToOffset.value = nextOffset;
99-
}, false);
100+
}, [
101+
isFrameCallbackActive,
102+
isHorizontal,
103+
prevScrollToOffset,
104+
scrollableRef,
105+
scrollOffset,
106+
speed,
107+
targetScrollOffset
108+
]);
109+
110+
const frameCallback = useFrameCallback(frameCallbackFunction, false);
100111

101112
const toggleFrameCallback = useCallback(
102113
(isEnabled: boolean) => frameCallback.setActive(isEnabled),

0 commit comments

Comments
 (0)