【问题标题】:How do you use navigator to go to another component in react-native?你如何使用 navigator 转到 react-native 中的另一个组件?
【发布时间】:2015-09-27 10:44:05
【问题描述】:

我有以下代码

InterfaceA 是另一个带有文本视图的反应组件。

目前,当我单击“转到另一个组件”时,它会一直返回到它自己的视图。

当我按下“转到另一个组件”时,它不会转到 interfaceA 视图。有谁知道我如何使用 navigator.push 去 interfaceA?

var ToolbarAndroidExample = React.createClass({

  _goA: function(navigator) {

    navigator.push({
      component: InterfaceA
    })
  },

  _goPrevious: function(navigator) {
    navigator.pop();
  },

  _renderScene: function(route, navigator) {

    return (
      <View>
          <TouchableHighlight onPress={() => this._goA(navigator) }>
            <Text> Go another component </Text>
          </TouchableHighlight>

          <TouchableHighlight onPress={() => this._goPrevious() }>
            <Text> Go previous</Text>
          </TouchableHighlight>
      </View>
    )
  },

  render: function() {
    return (

      <Navigator
        initialRoute={{ 
          message: "First Scene. Press me to go to the next scene.", index: 1
        }}
        renderScene={this._renderScene} />


    );
  },
});

【问题讨论】:

    标签: react-native


    【解决方案1】:

    查看 React Native 的示例:

    https://github.com/facebook/react-native/tree/master/Examples/UIExplorer/Navigator

    navigator.push({
      message: 'second page',
      index: 2
    })
    

    并根据路由改变_renderScene函数中的返回值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-11
      • 1970-01-01
      • 2021-08-15
      • 1970-01-01
      • 2020-04-21
      • 1970-01-01
      • 2023-03-04
      • 2019-02-06
      相关资源
      最近更新 更多