Skip to content

Commit aa1ef89

Browse files
committed
fix scrollToOffset
1 parent d542e86 commit aa1ef89

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/hooks/useAutoScroll.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,18 @@ export function useAutoScroll<T>() {
114114
isAutoScrollInProgress.current.native.setValue(1);
115115
isAutoScrollInProgress.current.js = true;
116116

117-
const flatlistNode: FlatList<T> | null =
118-
"scrollToOffset" in flatlistRef
119-
? flatlistRef
120-
: "getNode" in flatlistRef
121-
? //@ts-ignore backwards compat
122-
flatlistRef.getNode()
123-
: null;
124-
flatlistNode?.scrollToOffset?.({ offset });
117+
function getFlatListNode(): FlatList<T> | null {
118+
if (!flatlistRef.current) return null;
119+
if ("scrollToOffset" in flatlistRef.current)
120+
return flatlistRef.current as FlatList<T>;
121+
//@ts-ignore backwards compat
122+
if ("getNode" in flatlistRef.current) return flatlistRef.getNode();
123+
return null;
124+
}
125+
126+
const flatListNode = getFlatListNode();
127+
128+
flatListNode?.scrollToOffset?.({ offset });
125129
});
126130

127131
const getScrollTargetOffset = (

0 commit comments

Comments
 (0)