I’m not able to find a correct way to refresh a FlatList when bottom bar tab is pressed and that we are at the top of the FlatList.
I did succeed to reach the top of the FlatList using useScrollToTop
, also I managed to refetch data but it is not as I would like to be.
import { useScrollToTop } from '@react-navigation/native';
const flatlistRef = useRef<FlatList>(null);
useScrollToTop(flatlistRef);
This scroll to the top of the FlatList but :
- I want to refetch only if top is already reached when pressing bottom bar tab
- Using this I don’t have the refresh control animation to see that something is refetching (it’s just refetching underground)
I’m using React-Navigation for bottom tabs ("@react-navigation/bottom-tabs": "^6.5.16"
)
Any idea?
Thanks
2
Answers
Found a solution to this — might be better answer if so feel free to respond!
Didn't really understand
useScrollToTop(useRef({ scrollToTop }))
this, but it works — feel free to explain!Since you want to do more than just scroll to the top when the tab is focused, you should give up on using
useScrollToTop
and just use useFocusEffect. The hook is called whenever the current tab comes into focus. You can both refresh the data and scroll to the top of the flatlist in this hook (demo):