Skip to content

Commit 92e47cf

Browse files
committed
fix: auto scroll fix
1 parent 0fb074b commit 92e47cf

File tree

6 files changed

+16
-30
lines changed

6 files changed

+16
-30
lines changed

example/src/screens/usage/FlatList.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ const FlatList: React.FC<FlatListUsageScreenNavigationProps> = () => {
8686
getItemLayout={(_, index) => ({ index, length: ITEM_HEIGHT, offset: index * ITEM_HEIGHT })}
8787
initialNumToRender={50}
8888
maxToRenderPerBatch={100}
89-
disableAutoFixScroll
9089
keyExtractor={(_, i) => `text-row-${i}`}
9190
/>
9291
);

example/src/screens/usage/SectionList.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ const SectionList: React.FC<SectionListUsageScreenNavigationProps> = () => {
105105
getItemLayout={(_, index) => ({ index, length: ITEM_HEIGHT, offset: index * ITEM_HEIGHT })}
106106
initialNumToRender={50}
107107
maxToRenderPerBatch={100}
108-
disableAutoFixScroll
109108
keyExtractor={(_, i) => `text-row-${i}`}
110109
/>
111110
);

src/components/containers/FlatList.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useImperativeHandle } from 'react';
22
import { View, FlatListProps, StyleSheet } from 'react-native';
33
import { useSafeAreaInsets } from 'react-native-safe-area-context';
44
import Animated, { useAnimatedRef, AnimateProps } from 'react-native-reanimated';
@@ -28,15 +28,16 @@ const FlatListWithHeadersInputComp = <ItemT extends unknown>(
2828
onMomentumScrollEnd,
2929
ignoreLeftSafeArea,
3030
ignoreRightSafeArea,
31-
disableAutoFixScroll,
31+
disableAutoFixScroll = false,
3232
/** At the moment, we will not allow overriding of this since the scrollHandler needs it. */
3333
onScroll: _unusedOnScroll,
3434
...rest
3535
}: AnimatedFlatListProps<ItemT> & SharedScrollContainerProps,
36-
ref: React.Ref<AnimatedFlatListType<ItemT>>
36+
ref: React.Ref<Animated.FlatList<ItemT> | null>
3737
) => {
3838
const insets = useSafeAreaInsets();
3939
const scrollRef = useAnimatedRef<Animated.FlatList<ItemT>>();
40+
useImperativeHandle(ref, () => scrollRef.current);
4041

4142
const {
4243
scrollY,
@@ -63,12 +64,7 @@ const FlatListWithHeadersInputComp = <ItemT extends unknown>(
6364
>
6465
{HeaderComponent({ showNavBar })}
6566
<Animated.FlatList
66-
ref={(_ref) => {
67-
// @ts-ignore
68-
scrollRef.current = _ref;
69-
// @ts-ignore
70-
if (ref) ref.current = _ref;
71-
}}
67+
ref={scrollRef}
7268
scrollEventThrottle={16}
7369
overScrollMode="auto"
7470
onScroll={scrollHandler}

src/components/containers/ScrollView.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useImperativeHandle } from 'react';
22
import { View, StyleSheet } from 'react-native';
33
import { useSafeAreaInsets } from 'react-native-safe-area-context';
44
import Animated, { useAnimatedRef } from 'react-native-reanimated';
@@ -25,16 +25,17 @@ const ScrollViewWithHeadersInputComp = (
2525
onScrollEndDrag,
2626
onMomentumScrollBegin,
2727
onMomentumScrollEnd,
28-
disableAutoFixScroll,
28+
disableAutoFixScroll = false,
2929
children,
3030
/** At the moment, we will not allow overriding of this since the scrollHandler needs it. */
3131
onScroll: _unusedOnScroll,
3232
...rest
3333
}: AnimatedScrollViewProps & SharedScrollContainerProps,
34-
ref: React.Ref<Animated.ScrollView>
34+
ref: React.Ref<Animated.ScrollView | null>
3535
) => {
3636
const insets = useSafeAreaInsets();
3737
const scrollRef = useAnimatedRef<Animated.ScrollView>();
38+
useImperativeHandle(ref, () => scrollRef.current);
3839

3940
const {
4041
scrollY,
@@ -61,12 +62,7 @@ const ScrollViewWithHeadersInputComp = (
6162
>
6263
{HeaderComponent({ showNavBar })}
6364
<Animated.ScrollView
64-
ref={(_ref) => {
65-
// @ts-ignore
66-
scrollRef.current = _ref;
67-
// @ts-ignore
68-
if (ref) ref.current = _ref;
69-
}}
65+
ref={scrollRef}
7066
scrollEventThrottle={16}
7167
overScrollMode="auto"
7268
onScroll={scrollHandler}

src/components/containers/SectionList.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useImperativeHandle } from 'react';
22
import { View, SectionList, StyleSheet, SectionListProps } from 'react-native';
33
import { useSafeAreaInsets } from 'react-native-safe-area-context';
44
import Animated, { useAnimatedRef } from 'react-native-reanimated';
@@ -32,7 +32,7 @@ const SectionListWithHeadersInputComp = <ItemT extends any = any, SectionT = Def
3232
onMomentumScrollEnd,
3333
ignoreLeftSafeArea,
3434
ignoreRightSafeArea,
35-
disableAutoFixScroll,
35+
disableAutoFixScroll = false,
3636
/** At the moment, we will not allow overriding of this since the scrollHandler needs it. */
3737
onScroll: _unusedOnScroll,
3838
...rest
@@ -41,6 +41,7 @@ const SectionListWithHeadersInputComp = <ItemT extends any = any, SectionT = Def
4141
) => {
4242
const insets = useSafeAreaInsets();
4343
const scrollRef = useAnimatedRef<any>();
44+
useImperativeHandle(ref, () => scrollRef.current);
4445

4546
const {
4647
scrollY,
@@ -67,12 +68,7 @@ const SectionListWithHeadersInputComp = <ItemT extends any = any, SectionT = Def
6768
>
6869
{HeaderComponent({ showNavBar })}
6970
<AnimatedSectionList
70-
ref={(_ref) => {
71-
// @ts-ignore
72-
scrollRef.current = _ref;
73-
// @ts-ignore
74-
if (ref) ref.current = _ref;
75-
}}
71+
ref={scrollRef}
7672
scrollEventThrottle={16}
7773
overScrollMode="auto"
7874
onScroll={scrollHandler}

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
"strict": true,
2626
"target": "esnext"
2727
},
28-
"include": ["src", "babel.config.js"],
29-
"exclude": ["node_modules", "lib", "docs", "example"]
28+
"include": ["src", "babel.config.js", "example"],
29+
"exclude": ["node_modules", "lib", "docs"]
3030
}

0 commit comments

Comments
 (0)