【问题标题】:Disable going back in react-native using react-navigation使用 react-navigation 禁用返回 react-native
【发布时间】:2019-02-02 03:35:16
【问题描述】:

我已经花了很多时间搜索并尝试不同的东西来禁用“用户”登录后的返回,但它表明 NavigationActions 不起作用。这是代码:

import { NavigationActions } from 'react-navigation';

const actionToDispatch = NavigationActions.reset({
    index: 0,
    actions: [NavigationActions.navigate('DrawerNavigator')] // Array!
  })

export default class LoginScreen extends React.Component {
    constructor(props) {
        super(props);
      }


  render() {

    return (
        <RkAvoidKeyboard
        style={styles.screen}
        onStartShouldSetResponder={ (e) => true}
        onResponderRelease={ (e) => Keyboard.dismiss()}>
        <View style={styles.content}>
            <Button title="Complete Login" onPress={()=>this.props.navigation.dispatch(actionToDispatch)}/>
          </View>
      </RkAvoidKeyboard>
    );
  }
}

我缩小了一点代码。发生的事情是调度操作不起作用。而且我得到了错误: undefined is not a function(evalating '_reactNavigation.NavigationActions ....) 所以它甚至没有编译。我有最新版本的 React-navigation(2.12.0)。

【问题讨论】:

    标签: reactjs react-native react-navigation


    【解决方案1】:

    首先,reset 动作不在NavigationActions 内部,所以你必须将NavigationActions.reset 更改为StackActions.reset (docs here)。

    在这种情况下我要做的是StackActions.replace 而不是NavigationActions.navigatereplace 所做的就像卸载当前视图并安装给定的视图,因此当用户想要从第一个屏幕(登录)goBack() 时,它会退出应用程序而不是导航回 Login

    【讨论】:

      猜你喜欢
      • 2018-12-03
      • 1970-01-01
      • 2018-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多