Roc*_*cky 3 lifecycle react-native react-navigation
我有一个页面 A,然后导航到页面 B,然后返回。我想知道在 A 上会调用哪个生命周期方法,或者会发出事件?
使用react-navigation 时,您可以订阅didFocus和didBlur事件,以便在用户导航到屏幕或从屏幕导航时收到通知。
您可以componentDidMount使用如下所示的addListener方法在您的组件中设置这些this.props.navigation:
componentDidMount() {
this.props.navigation.addListener("didFocus", () => {
// user has navigated to this screen
});
this.props.navigation.addListener("didBlur", () => {
// user has navigated away from this screen
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1487 次 |
| 最近记录: |