Skip to content

Commit 8b50f35

Browse files
ericdolsonEric Olson
andauthored
Adding onPlaceholderIndexChange callback prop functionality (#446)
Co-authored-by: Eric Olson <[email protected]>
1 parent 07f5392 commit 8b50f35

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/components/DraggableFlatList.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ function DraggableFlatListInner<T>(props: DraggableFlatListProps<T>) {
225225
}
226226
);
227227

228+
const onPlaceholderIndexChange = useStableCallback((index: number) => {
229+
props.onPlaceholderIndexChange?.(index);
230+
});
231+
228232
// Handle case where user ends drag without moving their finger.
229233
useAnimatedReaction(
230234
() => {
@@ -245,6 +249,18 @@ function DraggableFlatListInner<T>(props: DraggableFlatListProps<T>) {
245249
[isTouchActiveNative, onDragEnd]
246250
);
247251

252+
useAnimatedReaction(
253+
() => {
254+
return spacerIndexAnim.value;
255+
},
256+
(cur, prev) => {
257+
if (cur !== prev && cur >= 0 && prev >= 0) {
258+
runOnJS(onPlaceholderIndexChange)(cur)
259+
}
260+
},
261+
[spacerIndexAnim]
262+
);
263+
248264
const gestureDisabled = useSharedValue(false);
249265

250266
const panGesture = Gesture.Pan()

0 commit comments

Comments
 (0)