Skip to content

Commit

Permalink
Applied changes from main.
Browse files Browse the repository at this point in the history
  • Loading branch information
fvlvte committed Dec 4, 2023
1 parent c3b70e5 commit 50c02eb
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/components/FlatList/index.android.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import {useFocusEffect} from '@react-navigation/native';
import React, {ForwardedRef, forwardRef, useCallback, useState} from 'react';
import React, {ForwardedRef, forwardRef, useCallback, useContext} from 'react';
import {FlatList, FlatListProps} from 'react-native';

type ScrollPosition = {offset?: number};
import {ActionListContext} from '@pages/home/ReportScreenContext';

// FlatList wrapped with the freeze component will lose its scroll state when frozen (only for Android).
// CustomFlatList saves the offset and use it for scrollToOffset() when unfrozen.
function CustomFlatList<T>(props: FlatListProps<T>, ref: ForwardedRef<FlatList>) {
const [scrollPosition, setScrollPosition] = useState<ScrollPosition>({});
const {scrollPosition, setScrollPosition} = useContext(ActionListContext);

const onScreenFocus = useCallback(() => {
if (typeof ref === 'function') {
return;
}
if (!ref?.current || !scrollPosition.offset) {
if (!ref?.current || !scrollPosition?.offset) {
return;
}
if (ref.current && scrollPosition.offset) {
ref.current.scrollToOffset({offset: scrollPosition.offset, animated: false});
}
}, [scrollPosition.offset, ref]);
}, [scrollPosition?.offset, ref]);

useFocusEffect(
useCallback(() => {
Expand Down

0 comments on commit 50c02eb

Please sign in to comment.