React Native redux和react-navigation配合物理键盘返回问题

constructor(props) {
    super(props);
    this.state = {        
    }
    this.onBackPress = this.onBackPress.bind(this);
  }
  componentDidMount() {
    SplashScreen.hide();
    BackHandler.addEventListener('hardwareBackPress', this.onBackPress);
    
  }
  componentWillUnmount() {
     BackHandler.removeEventListener('hardwareBackPress', this.onBackPress)
  }
  onBackPress = () => {
    const {dispatch, nav} = this.props;
    if (nav.routes[0].index === 0) {//如果RootNavigator中的MainNavigator的index为0,则不处理返回事件
        ToastAndroid.show('善赞提示您:已经退出应用!', ToastAndroid.SHORT);
        return false;
    }
    dispatch(NavigationActions.back());
    return true;
  };

你可能感兴趣的:(react,native)