Skip to content

Commit 8771fbc

Browse files
author
tfomkin
committed
fix: reset scroll position only after auto refresh
1 parent 46cc35b commit 8771fbc

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

libs/mobile/chat/features/menu-list/src/lib/component.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff 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} />}

0 commit comments

Comments
 (0)