I have a app, it contains many screen and I want to detect current screen when I change state app.
I use AppState to catch event change active
and inactive
app.
In React Navigation v5, use useIsFocused
to determine if a screen is in focus: https://reactnavigation.org/docs/use-is-focused
v4 and earlier, you’ll want withNavigationFocus
: https://reactnavigation.org/docs/4.x/with-navigation-focus
Heads-up that there’s a nasty nasty bug with this in react-navigation 4.x that you’ll have to work around: https://github.com/react-navigation/react-navigation/issues/4867
Anyway, our app uses withNavigationFocus to check if the screen is focused after the AppState listener is called when the app becomes active to determine if we should refresh that screen, and it works well (notwithstanding the bug).
1 Like
I didn’t know I needed this!
1 Like