starlight36 / react-native-navigator-router

Integration React Native and React Router with navigator.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

android系统的back键如何处理的?

shapenlone opened this issue · comments

在android系统中。按后退键后报错。楼主有木有如何具体处理后退键的代码。比如在tab界面两次按后退键退出系统。

可以尝试在子组件中通过this.props.addBackButtonListenerthis.props.removeBackButtonListener来处理

不的组件是有点bug吧

    handleBackButton() {
      for (let i = this.backHandlers.length - 1; i >= 0; i--) {
        if (this.backHandlers[i]()) {
          return true;
        }
      }

      const { navigator } = this.refs;
      if (navigator) {
        return this.props.onBack.apply(this, [navigator.getCurrentRoutes().length]);
      }

      return false;
    }

你的demo没有传递 onBack 就会报错 。你的demo就没传递 所有andoid返回就会报错

export function createNavigatorRouter(onBack = null, style = {}) {
  if (!onBack) {
    onBack = function (index) {
      if (index > 1) {
        this.context.router.goBack();
        return true;
      }

      return false;
    };
  }

直接传递的参数 这个onBack也没看到你哪里有使用

@yuanmao5200 感谢反馈,的确是个Bug,对Android系统测试不够。欢迎PR,或者等待我修正这个问题。