react native 从另一个页面返回时会调用哪个生命周期方法?
Which life cycle method will be called when returning from another page in react native?
我有一个页面 A,然后导航到页面 B,然后返回。我想知道在 A 上会调用哪个生命周期方法,或者会发出事件?
使用 react-navigation 时,您可以订阅 didFocus
和 didBlur
事件,以便在用户导航到屏幕或从屏幕导航时收到通知。
您可以使用 this.props.navigation
的 addListener 方法在组件的 componentDidMount
中设置这些,如下所示:
componentDidMount() {
this.props.navigation.addListener("didFocus", () => {
// user has navigated to this screen
});
this.props.navigation.addListener("didBlur", () => {
// user has navigated away from this screen
});
}
我有一个页面 A,然后导航到页面 B,然后返回。我想知道在 A 上会调用哪个生命周期方法,或者会发出事件?
使用 react-navigation 时,您可以订阅 didFocus
和 didBlur
事件,以便在用户导航到屏幕或从屏幕导航时收到通知。
您可以使用 this.props.navigation
的 addListener 方法在组件的 componentDidMount
中设置这些,如下所示:
componentDidMount() {
this.props.navigation.addListener("didFocus", () => {
// user has navigated to this screen
});
this.props.navigation.addListener("didBlur", () => {
// user has navigated away from this screen
});
}