【问题标题】:How to pass props between screens when using react-native-router-flux使用 react-native-router-flux 时如何在屏幕之间传递道具
【发布时间】:2018-10-30 04:56:47
【问题描述】:

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 状态变量作为道具传递给 SignIn 组件。然后,在成功调用我的身份验证服务后的 SignIn 回调中,我可以更新 prop 并返回 App.js,而不是渲染 SignIn/SignUp,AppNavigator 组件将被渲染。

我无法找到有关如何在它们之间传递这些值的文档或示例。

Passing props in react-native-flux-router

我找到了上面的这个例子,但我对 prop 被分配给 handleClick 的事实感到困惑

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

我还发现了这个例子,它看起来很有希望,但我不确定 Actions.key{props} 的去向。此人似乎已将其分配给 onPress。

我的问题是我没有使用点击在此处的场景之间导航。我在 SignIn 和 SignUp 中使用 Action 对象。

抱歉,我知道这是漫无边际的,但我希望有人以前看过。

【问题讨论】:

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


    【解决方案1】:

    如果我没看错,你想调用一个动作并将一个变量作为属性传递。 Actions.signIn({ isAuthenticated: true });

    然后在signIn 场景中使用isAuthenticated 属性和this.props.isAuthenticated

    或者如果您想将函数作为属性传递:

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

    然后在您的signIn 中调用this.props.doMagic(); 并调用myFunction

    【讨论】:

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