React-navigation: detect new screen is fully focused

对着背影说爱祢 提交于 2019-12-23 12:45:28

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/50027713/react-navigation-detect-new-screen-is-fully-focused

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!