Skip to content

Commit fcd2896

Browse files
committed
check for "scrollToOffset" on ref before calling
1 parent 02a575d commit fcd2896

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/index.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
FlatList,
1616
PanGestureHandlerStateChangeEvent,
1717
PanGestureHandlerGestureEvent,
18+
PanGestureHandlerProperties,
1819
} from "react-native-gesture-handler";
1920
import Animated from "react-native-reanimated";
2021
import { springFill, setupCell } from "./procs";
@@ -75,7 +76,7 @@ const defaultProps = {
7576
autoscrollSpeed: 100,
7677
animationConfig: defaultAnimationConfig,
7778
scrollEnabled: true,
78-
dragHitSlop: 0,
79+
dragHitSlop: 0 as PanGestureHandlerProperties["hitSlop"],
7980
activationDistance: 0,
8081
dragItemOverflow: false,
8182
};
@@ -617,7 +618,16 @@ class DraggableFlatList<T> extends React.Component<
617618
this.isAutoScrollInProgress.native.setValue(1);
618619
this.isAutoScrollInProgress.js = true;
619620
const flatlistRef = this.flatlistRef.current;
620-
if (flatlistRef) flatlistRef.scrollToOffset({ offset });
621+
if (flatlistRef) {
622+
const flatlistNode: FlatList<T> | null =
623+
"scrollToOffset" in flatlistRef
624+
? flatlistRef
625+
: "getNode" in flatlistRef
626+
? //@ts-ignore backwards compat
627+
flatlistRef.getNode()
628+
: null;
629+
flatlistNode?.scrollToOffset?.({ offset });
630+
}
621631
});
622632

623633
getScrollTargetOffset = (

0 commit comments

Comments
 (0)