首页 文章

导航屏幕 - React Native

提问于
浏览
0

我创建了一个简单的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);

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

1 回答

  • 0

    First ,永远不会调用您的导出默认类SimpleNavigationApp .

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

    .

    Second ,不再支持从'react-native'导入 .

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

相关问题