导航屏幕 - React Native

时间:2017-06-11 10:01:27

标签: android react-native react-native-android react-native-navigation

我创建了一个简单的Android应用,可以在按下文本时更改导航。该应用程序运行正常,但当我触摸文本时,内容不会更改,也没有观察到导航。您可以查看错误here。我还提供了代码:

import React, { Component, PropTypes } from 'react';
import { Navigator, Text, TouchableHighlight, View, AppRegistry} from 
'react-native';

export default class SimpleNavigationApp extends Component {
constructor(props){
  super(props);
  this.state={
    title: 'My Initial Scene',
  }
}

  render() {
    return (
      <Navigator
        initialRoute={{ title: 'My Initial Scene', index: 0 }}
        renderScene={(route, navigator) =>
          <MyScene
            title={route.title}

            // Function to call when a new scene should be displayed
            onForward={ () => {
              const nextIndex = route.index + 1;
              navigator.push({
                title: 'Scene ' + nextIndex,
                index: nextIndex,
              });
            }}

            // Function to call to go back to the previous scene
            onBack={() => {
              if (route.index > 0) {
                navigator.pop();
              }
            }}
          />
        }
      />
    )
  }
}

class dhrumil extends Component {
  static propTypes = {
    title: PropTypes.string.isRequired,
    onForward: PropTypes.func.isRequired,
    onBack: PropTypes.func.isRequired,
  }
  render() {
    return (
      <View>
        <Text>Current Scene: { this.props.title }</Text>
        <TouchableHighlight onPress={this.props.onForward}>
          <Text>Tap me to load the next scene</Text>
        </TouchableHighlight>
        <TouchableHighlight onPress={this.props.onBack}>
          <Text>Tap me to go back</Text>
        </TouchableHighlight>
      </View>
    )
  }
}

AppRegistry.registerComponent("dhrumil",()=>dhrumil);

正如您在错误中看到的那样,在“我的当前场景:”文本后,标题也不会显示。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

首先,永远不会调用您的导出默认类SimpleNavigationApp。

你应该将它放在另一个js文件中并将其导入dhrumil类

<强>第二下,     不再支持来自'react-native'的import {Navigator}。

阅读https://facebook.github.io/react-native/docs/navigation.html了解详细的导航文档。