【问题标题】:react-native-navigation how to detect current screen inside `shouldComponentUpdate`react-native-navigation如何在`shouldComponentUpdate`中检测当前屏幕
【发布时间】:2018-07-16 02:46:57
【问题描述】:

我正在使用 react-native-navigation 并使用 redux 进行状态管理。当我用“push”方法从screenA到screenB时,screenA不会卸载。这将导致不需要的重新渲染,之前在 react-navigation 中我使用 shouldComponentUpdate 将组件与当前可见的屏幕匹配以停止重新渲染。

有没有办法在 react-native-navigation 中做到这一点?

【问题讨论】:

    标签: reactjs react-native react-native-navigation wix-react-native-navigation


    【解决方案1】:

    当您设置导航器事件处理程序(使用addOnNavigatorEvent)时,您可以跟踪屏幕生命周期事件并在屏幕消失或出现时收到通知。

    或者,您可以使用await this.props.navigator.screenIsCurrentlyVisible() 检查屏幕当前是否可见,但我不确定在shouldComponentUpdate 中执行此操作的含义是什么,因为它执行需要过桥并可能添加的本机调用不必要的延误。

    您可以查看有关屏幕可见性的更多信息here

    【讨论】:

      猜你喜欢
      • 2020-05-29
      • 2017-12-31
      • 2018-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      相关资源
      最近更新 更多