React Native-NavigationActions.navigate()不从Redux内部导航

Shi*_*vam 5 reactjs react-native redux-saga react-redux react-navigation

我有两个导航器,一个是stackNavigator,另一个是抽屉导航器。我要执行的操作是分派操作并成功登录,然后将用户重定向到抽屉式导航器。我已经使用了反应导航。我所做的是,我正在传奇中分派动作登录成功。使用NavigationActions.navigate({ routeName: 'drawerStack' })派遣行动。该动作成功分派,但没有导航到抽屉导航器,如下图所示。我究竟做错了什么?

在此处输入图片说明

saga.js

function* watchLoginRequest() {
  while (true) {
    const { state } = yield take(LOGIN_REQUEST);

    try {
      const payload = {
        state
      };
      const response = yield call(loginCall, payload);
      yield put(loginSuccess(response));
      yield setUser(response.user);
      yield put(NavigationActions.navigate({ routeName: 'drawerStack' }));
    } catch (err) {
      yield put(loginFailure(err.status));
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

cabinetNavigation.js

// drawer stack
const DrawerStack = DrawerNavigator({
  testComponent: { screen: TestComponent },
});

const DrawerNav = StackNavigator({
  drawerStack: { screen: DrawerStack }
}, {
  headerMode: 'float',
  navigationOptions: ({ navigation }) => ({
    headerStyle: { backgroundColor: 'green' },
    title: 'Logged In to your app!',
    headerLeft: <Text onPress={() => navigation.navigate('DrawerOpen')}>Menu</Text>
  })
});

export default DrawerNav;
Run Code Online (Sandbox Code Playgroud)

loginNavigation.js

// login stack
const LoginStack = StackNavigator({

  startScreen: { screen: StartScreen },
  loginScreen: { screen: LoginScreen },
  personalInformation: { screen: PersonalInformation },
  vehicleInformation: { screen: VehicleInformation },
  availability: { screen: Availability },
  selectRegisteration: { screen: SelectRegisteration },
  serviceAddress: { screen: ServiceAddress },

}, {
  headerMode: 'none',
  transitionConfig: TransitionConfiguration

});


export default LoginStack;
Run Code Online (Sandbox Code Playgroud)

ReduxNavigation.js

class ReduxNavigation extends React.Component {
  constructor(props) {
    super(props);
    const { dispatch, nav } = props;
    const navigation = ReactNavigation.addNavigationHelpers({
      dispatch,
      state: nav
    });
    this.state = {
      loggedInStatus: false,
      checkedSignIn: false
    };
  }

  componentWillMount() {
    isSignedIn()
      .then(res => {
        if (res !== null) {
          this.setState({
            loggedInStatus: true,
            checkedSignIn: true
          });
        } else {
          console.log(res);
        }
      })
      .catch(err => console.log(err));
  }

  render() {
    return <LoginNavigation navigation={this.navigation} />;
  }
}

const mapStateToProps = state => ({ nav: state.nav });
export default connect(mapStateToProps)(ReduxNavigation);
Run Code Online (Sandbox Code Playgroud)

Col*_*ung 0

导航到TestComponent您想要的routeName位置testComponent,而不是抽屉堆。您导航到特定屏幕,而不是导航组件。