如何使用反应本地路由器通量时,通过屏幕之间的道具

问题描述 投票:0回答:1

App.js剪断

  render() {
      if (!this.state.isLoadingComplete && !this.props.skipLoadingScreen) {
          return (
              <AppLoading
                  startAsync={this._loadResourcesAsync}
                  onError={this._handleLoadingError}
                  onFinish={this._handleFinishLoading}
              />
          );
      } else if (!this.state.isAuthenticated) {
          return (
              <Router>
                  <Scene key="root">
                      <Scene key="signIn"
                             component={SignIn}
                             title="Scarlet"
                             initial
                      />
                      <Scene
                          key="signUp"
                          component={SignUp}
                          title="Gray"
                      />
                 </Scene>
              </Router>
          )
      } else {
          return (
              <AppNavigator/>
          )
      }
  }

我想这样做的是通过isAuthenticated状态变量进入签到组件作为道具。然后,在成功调用我的认证服务后,登入回调里面我可以更新道具,背App.js而不是登入/注册所呈现的AppNavigator部分将被渲染。

我无法找到文件或之间如何传递这些价值的例子。

Passing props in react-native-flux-router

我发现这上面的例子,但我通过道具分配给handleClick的事实感到困惑

How to pass values to other component in React-Native-Router-Flux?

我也发现了这个例子,这似乎很有前途,但我不知道在哪里的Actions.key {}道具去。这个人似乎有它分配给onPress。

我的问题是,我没有使用点击这里的场景之间进行导航。我使用的是内登入和注册的Action对象。

对不起,我知道这是散漫的,但我希望有人将有见过这个。

react-native react-native-router-flux
1个回答
1
投票

如果我读这个权利,你要调用一个Action,并传递一个变量作为属性。 Actions.signIn({ isAuthenticated: true });

然后你在isAuthenticated场景中使用此signIn属性与this.props.isAuthenticated

或者,如果你想通过一个函数作为一个属性:

let myFunction = () => {
  //do some magic here
}; 
Actions.signIn({ doMagic: myFunction });

然后在你的signIn你打电话this.props.doMagic();myFunction被调用。

© www.soinside.com 2019 - 2024. All rights reserved.