File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ export function ChatMenuList({
4040 const chatActionsSheetRef = useRef < ChatActionsMenuSheetMethods > ( null ) ;
4141 const listRef = useRef < FlashList < ChatListItem > > ( null ) ;
4242 const previousIsRefetchingRef = useRef < boolean > ( false ) ;
43+ const scrollOffsetRef = useRef ( 0 ) ;
4344
4445 const [ isFirstLoading , setIsFirstLoading ] = useState < boolean > ( true ) ;
4546
@@ -89,11 +90,14 @@ export function ChatMenuList({
8990 [ onChatPress ] ,
9091 ) ;
9192
92- // NOTE: Reset scroll position when refresh completes to remove extra space left by refresh control
93+ // NOTE: Reset scroll position when auto refresh completes to remove extra space left by refresh control
9394 useEffect ( ( ) => {
94- if ( previousIsRefetchingRef . current && ! isRefetching && listRef . current ) {
95+ const wasRefetching = previousIsRefetchingRef . current ;
96+
97+ if ( wasRefetching && ! isRefetching && listRef . current && scrollOffsetRef . current > 0 ) {
9598 listRef . current . scrollToOffset ( { offset : 0 , animated : false } ) ;
9699 }
100+
97101 previousIsRefetchingRef . current = isRefetching ;
98102 } , [ isRefetching ] ) ;
99103
@@ -110,6 +114,9 @@ export function ChatMenuList({
110114 data = { chats || [ ] }
111115 estimatedItemSize = { 52 }
112116 renderItem = { renderItem }
117+ onScroll = { ( e ) => {
118+ scrollOffsetRef . current = e . nativeEvent . contentOffset . y ;
119+ } }
113120 transformSectionTitle = { transformSectionTitle }
114121 onEndReached = { fetchNextPage }
115122 refreshControl = { < AppRefreshControl onRefresh = { refetch } refreshing = { isRefetching } /> }
You can’t perform that action at this time.
0 commit comments