【问题标题】:Unable to switch scenes after nesting嵌套后无法切换场景
【发布时间】:2018-12-29 16:24:06
【问题描述】:

我能够切换到员工列表,但我得到了返回按钮。所以我尝试将它们嵌套到单独的场景中,但是当我尝试嵌套场景时,它将不再导航到下一个场景。这是我的代码。

在我的索引操作文件的底部,我有一个名为 loginUserSuccess 的操作,在 loginUserSuccess 操作内是 Actions.employeeList() 行。

我仍在使用与employeeList 相同的场景键。

src/actions/index.js

import firebase from '@firebase/app';
import { Actions } from 'react-native-router-flux';
import {
  EMAIL_CHANGED,
  LOGIN_USER,
  LOGIN_USER_FAIL,
  LOGIN_USER_SUCCESS,
  PASSWORD_CHANGED
} from './types';

export const emailChanged = text => {
  return {
    type: EMAIL_CHANGED,
    payload: text
  };
};

export const passwordChanged = text => {
  return {
    type: PASSWORD_CHANGED,
    payload: text
  };
};

export const loginUser = ({ email, password }) => {
  return dispatch => {
    dispatch({ type: LOGIN_USER });

    firebase
      .auth()
      .signInWithEmailAndPassword(email, password)
      .then(user => loginUserSuccess(dispatch, user))
      .catch(error => {
        console.log(error);
        firebase
          .auth()
          .createUserWithEmailAndPassword(email, password)
          .then(user => loginUserSuccess(dispatch, user))
          .catch(() => loginUserFail(dispatch));
      });
  };
};

const loginUserFail = dispatch => {
  dispatch({ type: LOGIN_USER_FAIL });
};

const loginUserSuccess = (dispatch, user) => {
  dispatch({
    type: LOGIN_USER_SUCCESS,
    payload: user
  });
  console.log(Actions.currentScene);
  Actions.employeeList();
  console.log(Actions.currentScene);
};

在这个路由器文件中,我将登录场景嵌套在了 auth 场景中,并将employeeList 场景嵌套在了主场景中。这就是我切换场景的问题开始的地方。

src/Router.js

import React from 'react';
import { Scene, Router } from 'react-native-router-flux';
import LoginForm from './components/LoginForm';
import EmployeeList from './components/EmployeeList';

const RouterComponent = () => {
  const { navigationBarTitleStyle } = styles;

  return (
    <Router>
      <Scene key="root">
        <Scene key="auth">
          <Scene
            key="login"
            component={LoginForm}
            title="Please Login"
            titleStyle={navigationBarTitleStyle}
            initial
          />
        </Scene>
        <Scene key="main">
          <Scene
            key="employeeList"
            component={EmployeeList}
            title="Employee List"
            titleStyle={navigationBarTitleStyle}
          />
        </Scene>
      </Scene>
    </Router>
  );
};

const styles = {
  navigationBarTitleStyle: {
    flex: 1,
    textAlign: 'center'
  }
};

export default RouterComponent;

有人知道可能是什么问题吗?我正在关注 Stephen Grider 的 Udemy 上的完整 React Native 和 Redux 课程指南,但是 React Native 是一个快速发展的目标。

【问题讨论】:

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


    【解决方案1】:

    我发现了问题所在,我需要更改我的 Actions.employeeList();到 Actions.main();在 src/actions/index.js 文件中。

    我需要在该场景中定位父母而不是孩子。然后它将加载主场景中的第一个场景。我还可以在employeeList 上设置initial 以便更清楚地了解它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-21
      • 1970-01-01
      • 1970-01-01
      • 2018-04-08
      • 1970-01-01
      相关资源
      最近更新 更多