2

我正在开发一个反应原生应用程序。我正在使用react-native-router-flux库在应用程序中进行导航。

该库工作正常,但在返回导航时没有调用任何反应生命周期方法。

假设例如我在第 2 页上按下后退按钮,它导航到第 1 页并且第 2 页的 componentWillUnmount() 被调用,但第 1 页的生命周期方法没有被调用

我想根据新状态刷新页面 1。

任何帮助将不胜感激。

4

1 回答 1

0

向后导航时,默认情况下Actions.pop()不带参数调用。为了刷新第 1 页,您需要覆盖后退按钮的功能并调用Actions.pop({refresh:{<propsToSetToPage1>}}). 这应该componentWillReceiveProps(nextProps)在第 1 页触发,其中 nextProps 是您放入 pop() 中的新道具。

以下来自 react-native-router-flux 的文档:

Actions.pop() will pop the current screen. It accepts following optional params:
    {popNum: [number]} allows to pop multiple screens at once
    {refresh: {...propsToSetOnPreviousScene}} allows to refresh the props of the scene that it pops back to

PS。如果您正在为 Android 开发,您可能也想在用户按下硬件后退按钮时执行此操作。在 React Native 的官方文档中查看BackAndroid 。

于 2016-09-28T16:57:11.907 回答