From 50c02ebdb20a589e64b0e33e13a7dfb2f70e2904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20=27fvlvte=27=20Fa=C5=82at?= Date: Mon, 4 Dec 2023 09:47:51 +0100 Subject: [PATCH] Applied changes from main. --- src/components/FlatList/index.android.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/components/FlatList/index.android.tsx b/src/components/FlatList/index.android.tsx index a230fe28f76a..84345f6e0ed4 100644 --- a/src/components/FlatList/index.android.tsx +++ b/src/components/FlatList/index.android.tsx @@ -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(props: FlatListProps, ref: ForwardedRef) { - const [scrollPosition, setScrollPosition] = useState({}); + 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(() => {