Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-navigation: detect new screen is fully focused

With current version of react-navigation, there are two ways to check if a screen is focused or not, by either (1) calling function isFocused of screen's prop navigation, or (2) hook the component to withNavigationFocused and retrieve prop isFocused.

However, both methods always return true when navigation starts. In my case, I need something triggering only when screen transition ends, i.e. new screen is fully focused. This is to deal with heavy-rendered children, such as camera or map, which should be rendered after screen transition to avoid slow transition animation.

Any idea how to achieve that?

like image 451
blaz Avatar asked Jan 03 '23 11:01

blaz


1 Answers

You can try subscribing to the navigation lifecycle events, as described in the docs:

const didFocusSubscription = this.props.navigation.addListener(
  'didFocus',
  payload => {
    console.debug('didFocus', payload);
  }
);

Another example usage in this repo

like image 103
vonovak Avatar answered Jan 05 '23 00:01

vonovak