【问题标题】:How to configure react-native-router-flux android back history?如何配置 react-native-router-flux android 返回历史记录?
【发布时间】:2019-08-09 02:06:59
【问题描述】:

我有这个使用 react-native-router-flux 进行导航配置和阶段的反应原生应用程序,问题是我无法完全理解如何设置 android 历史记录,因此后退按钮可以使用。

这是我的视图层次结构:

<Router>
 <Stack hideNavBar key="root"> 
    <Scene back key="mainMenu" component={MainMenu}/>
    <Scene key="about" component={About}/>
    //... and so on
</Router>

但是如果我在呈现带有动作的视图后按下返回按钮,例如:

Actions.about();

在 about 视图中我按下返回 android 按钮,我收到以下错误消息:

"undefined is not an object (evaluating that.props.navigation.navigate)"

我真的不知道我做错了什么。请问有人可以帮帮我吗?

【问题讨论】:

    标签: react-native react-navigation react-native-router-flux


    【解决方案1】:

    如果你想把屏幕往回移动,你可以用一个简单的命令来解决。

    
     componentDidMount() {
        this.backHandler = BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
      }
    
      componentWillUnmount() {
        this.backHandler.remove()
      }
    
      handleBackPress = () => {
        // go back (i.e. pop the current screen off the nav stack)
        Actions.pop()
        return true;
      }
    

    【讨论】:

    • 问题是android后退按钮给了我错误。在我的 UI 中,我已经在使用 Actions.pop() 返回之前的视图。
    • 不,使用pop() 时没有错误。仅在 android 上按返回按钮时发生错误。
    • @KarloA.López 你的意思是后退按钮 Android 的唯一?是设备后退按钮吗?
    • 是的,就是这样。我尝试添加一些侦听器,但错误继续出现!
    猜你喜欢
    • 2015-09-04
    • 1970-01-01
    • 2017-05-10
    • 2017-07-29
    • 1970-01-01
    • 2017-07-04
    • 2019-12-15
    • 2017-12-08
    • 2018-01-22
    相关资源
    最近更新 更多