本机基本抽屉单击导航到具有React-router-flux的根屏幕,也不会更改屏幕

时间:2019-03-19 17:57:52

标签: android reactjs react-native native-base react-native-router-flux

我正在使用带有react-router-flux导航和native-base的react-native应用程序。以下是版本-

"native-base": "^2.12.1",
"react": "16.8.3",
"react-native": "0.59.0",
"react-native-router-flux": "^4.0.6",

单击“登录”按钮后,屏幕移至首页,然后从那里打开抽屉,将其打开,但导航至登录屏幕。理想情况下,它应该在同一页面上。另外,我还添加了从抽屉导航的功能,它没有移动到新屏幕,后来我删除了它,因为首先必须解决此问题。

App.js

    const RouterWithRedux = connect()(Router);

class AppNavigator extends Component<{}> {
    static propTypes = {
        drawerState: PropTypes.string
    };

    componentDidUpdate() {
        if (this.props.drawerState === "opened") {
            this.drawer._root.open();
        }

        if (this.props.drawerState === "closed") {
            this.drawer._root.close();
        }
    }
    openDrawer() {
        this.drawer._root.open();
    }

    closeDrawer() {
         if (this.props.drawerState === "opened") {
            this.props.closeDrawer();
        } 
        //this.drawer._root.close();
    }

    render() {
        // eslint-disable-line class-methods-use-thisy
        return (
            <Drawer ref={(ref) => { this.drawer = ref; }}
                content={<SideBar navigator={this.navigator} />}
                onClose={() => this.closeDrawer()}
                type="overlay"
                tapToClose
                tweenHandler={ratio => {
                    //eslint-disable-line
                    return {
                        drawer: { shadowRadius: ratio < 0.2 ? ratio * 5 * 5 : 5 },
                        main: {
                            opacity: (2 - ratio) / 2
                        }
                    };
                }}

            >
                <StatusBar
                    backgroundColor={variables.brandPrimary}
                    barStyle="light-content"
                />
                <RouterWithRedux>
                        <Scene key="root" hideNavBar>
                            <Scene key="login" component={Login} hideNavBar initial={true} />
                            <Scene key="signIn" component={SignIn} />
                            <Scene key="home" component={Home} />
                            <Scene key="register" component={Register} />
                            <Scene key="sideBar" component={SideBar} />
                        </Scene>
                </RouterWithRedux>
            </Drawer >
        );
    }
}

const bindAction = (dispatch) => {
    return {
        closeDrawer: () => dispatch(closeDrawer())


      };
    };

    const mapStateToProps = state => ({
        drawerState: state.drawer.drawerState
    });

    export default connect(
        mapStateToProps,
        bindAction
    )(AppNavigator);

Login.js

 class Login extends Component {
  render() {
    return (
      <View style={{ flex: 1 }}>
        <View style={{ padding: 10, marginBottom: 60 }}>
          <Grid>
            <Col style={{ padding: 10 }}>
              <Button
                onPress={() => Actions.signIn()}
                transparent
                block
                style={styles.loginBtn}
              >
                <Text style={{ color: commonColor.brandPrimary, fontWeight: "600" }}>
                  SIGN IN
                </Text>
              </Button>
            </Col>
            <Col style={{ padding: 10 }}>
              <Button
                onPress={() => Actions.register()}
                block
                style={styles.registerBtn}
              >
                <Text style={{ fontWeight: "600", color: "#fff" }}>
                  REGISTER
                </Text>
              </Button>
            </Col>
          </Grid>
        </View>
      </View>
    );
  }
}

export default connect()(Login);

Home.js

class Home extends Component {
  constructor(props) {
    super(props);
  }

  render() {
    return (
      <View style={styles.container}>
        <Text>Page under construuction</Text>
        <View style={styles.headerContainer}>
          <Header
            iosStatusbar="default"
            style={Platform.OS === "ios" ? styles.iosHeader : styles.aHeader}
            androidStatusBarColor={commonColor.statusBarLight}
          >
            <Left>
              <Button transparent onPress={this.props.openDrawer}>
                <Icon
                  name="ios-menu"
                  style={{ color: commonColor.brandPrimary }}
                />
              </Button>
            </Left>
            <Body>
              <Title style={{ color: commonColor.brandPrimary, marginTop: -2 }}>
                Drawer Demo App
              </Title>
            </Body>
            <Right />
          </Header>
        </View>
      </View>
    );
  }
}
function bindActions(dispatch) {
  return {
    openDrawer: () => dispatch(openDrawer())
  };
}
const mapStateToProps = state => ({
  navigation: state.cardNavigation
});

export default connect(
  mapStateToProps,
  bindActions
)(Home);

0 个答案:

没有答案