当从本机的另一个页面返回时,将调用哪种生命周期方法?

时间:2018-11-06 03:02:41

标签: react-native react-navigation lifecycle

我有A页,然后导航到B页,然后返回。我想知道哪个生命周期方法将在A上调用,否则将发出事件?

1 个答案:

答案 0 :(得分:0)

使用react-navigation时,您可以订阅didFocusdidBlur事件,以便在用户导航到屏幕或从屏幕导航时得到通知。

您可以使用componentDidMount的{​​{3}}方法在组件的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
    });
}