-1

登录屏幕.js

this.props.navigator.push({
      screen: "auxxa.LandingScreen",
      passProps: { login: true },
      overrideBackPress: true,
      navigatorStyle: {
        navBarHidden: true
      }
    });

LandingScreen.js

 constructor(props) {
    super(props);
    this.handleBackButtonClick = this.handleBackButtonClick.bind(this);
    //  this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));
    this.state = {
      size: { width, height },
      tileData: null,
      isLoading: true,
      user_id: null,
      refetching: false,
      access_token: null
    };
  }
  componentWillMount() {
    BackHandler.addEventListener(
      "hardwareBackPress",
      this.handleBackButtonClick
    );
  }
  handleBackButtonClick() {
    console.log("check login " + this.props.login);
    if (this.backPressed && this.backPressed > 0) {
      if (this.props.login) {
        console.log("login");
        RNExitApp.exitApp();
      } else {
        console.log("root");
        this.props.navigator.popToRoot({ animated: false });
        return false;
      }
    }

    this.backPressed = 1;
    this.props.navigator.showSnackbar({
      text: "Press one more time to exit",
      duration: "long"
    });
    return true;
  }

  componentDidMount() {
    BackHandler.removeEventListener(
      "hardwareBackPress",
      this.handleBackButtonClick
    );
}

我使用Wix 的 react-native-navigation 来进行应用导航。这里我附加了登录屏幕和登录屏幕。成功登录后应用导航到登录屏幕。之后我点击返回按钮它将返回登录屏幕。我需要避免那个。我该怎么做?我试图退出应用程序。但它也无法正常工作。如果有人知道这一点,请帮助我。在此先感谢。

4

2 回答 2

1

在 handleBackButtonClick 函数中使用此调用,为什么要删除 componentDidMount 中的侦听器?

this.props.navigator.resetTo({  screen: 'example.ScreenThree'})

.

于 2018-07-23T12:23:26.733 回答
0

取消注释this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));您的构造函数以侦听导航事件并添加 navigationEvent 侦听器方法

onNavigatorEvent(event: NavigatorEvent) {
  if (event.type === 'NavBarButtonPress') {
    if (event.id === 'skill_information') {
      // Add here whatever you would like to do (this.handleBackButtonClick() for example)
    }
  }
于 2018-07-23T13:33:44.683 回答