代码之家  ›  专栏  ›  技术社区  ›  xiaolingxiao

响应本机在用户注册时重新启动应用程序

  •  0
  • xiaolingxiao  · 技术社区  · 8 年前

    我有一个响应本地应用程序,它的顶层 App.js 如下:

    const AuthStack = createStackNavigator(
    
        { Landing, SignUpWithGoogle },
    
        { 
              initialRouteName  : 'Landing' 
            , navigationOptions : {
                header : null
            }
        }
    );
    
    
    const AppStack = createStackNavigator(
    
        {   
              AppContainer
            , Campaign
            , Compose
        },
    
        { 
              initialRouteName  : 'AppContainer' 
            , navigationOptions : {
                header : null
            }
        }
    );
    
    
    /**
        @TODO: 
            force app to reload on user creation ... 
    
            there needs to be a state transition on user creation
            ... not sure how to 
    */
    class App extends React.Component {
    
        render () {
    
            const stack = (!this.props.authenticating && this.props.user)
                ? <AppStack  {...this.props} />
                : <AuthStack />
    
    
            return (
                <Loader
                    isLoaded        = { !this.props.authenticating && this.props.feedIsLoaded}
                    imageSource     = {logo}
                    backgroundStyle = {loading.loadingBackgroundStyle}
                >
                    {stack}
                </Loader>
            )
    
        }
    }
    

    有一个 Loader 组件从 https://github.com/TheSavior/react-native-mask-loader 这将隐藏带有初始页面的应用程序,直到应用程序获取用户身份验证数据或确定这是新用户。这非常有效,除非当用户第一次注册时,应用程序直接跳到验证模式,并且 无法加载初始数据 我想要的新用户。唯一能解决这个问题的是重启应用程序,这是一个不可行的做法。有没有办法在 AuthStack AppStack 最好让我注册时想要的信息都在那里?一种方法是强制 reload 这样我们就可以直接回到 装载机 屏幕和状态,但不清楚如何实现。

    1 回复  |  直到 8 年前
        1
  •  1
  •   Hariks    8 年前

    const Routes =  {
      Login: {
        screen: Login
      },
      Status: {
        screen: Status,
        navigationOptions: {
          gesturesEnabled: false,  // To prevent swipeback
        },
      },
    ...
    };
    
    const LoggedRootStack = createStackNavigator(
      {
        ...Routes
      },
      {
        initialRouteName: 'Status'
      }
    )
    
    const RootStack = createStackNavigator(
      {
        ...Routes
      },
      {
        initialRouteName: 'Login'
      }
    )
    

    Redux

    推荐文章