Undefined 不是对象( evaluate this.props.navigator.push')



我正在学习用于Android应用程序的react-native编程。我正在尝试按TouchableOpacity上的第二个屏幕。我正在使用navigator

我遇到此错误 undefined is not an object( evaluating this.props.navigator.push')

我已经检查了许多线程反应本机,navigatorios,undefined不是对象(评估this.props.navigator.push')undefined不是一个对象(kestue.props.navigator.push),但不是对象为我工作。我不确定我在这里做错了什么,任何人都可以帮我吗?预先感谢。

index.android.js

/**
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import { AppRegistry, Text, View, TextInput, TouchableOpacity, ToolbarAndroid, StyleSheet,Container,ScrollView, Navigator } from 'react-native';

class App extends Component {
  renderScene (route, navigator) {
    return <route.component navigator={navigator} />
  }
  render() {
    return (
        <Navigator
          style={styles.container}
          renderScene={this.renderScene.bind(this)}
          initialRoute={{component: LoginComponent}}
        />
    );
  }
}
class LoginComponent extends Component {
  _navigate () {
      this.props.navigator.push({
          component: DashboardComponent
      })
  }
  render() {
     return (
          <View style={{flex: 1, flexDirection: 'column'}}>
            <ToolbarAndroid title='LOGIN' titleColor='white'
                onIconClicked={() => this.props.navigator.pop()}
                style={styles.toolbar}/>
            <View style={{padding:10}}>
              <TextInput style={{height: 40, borderColor:'gray', borderWidth: .5}}
                  placeholder="Email address" underlineColorAndroid='transparent'/>
              <TextInput style={{height: 40, borderColor:'gray', borderWidth: .5}}
                  placeholder="Password" secureTextEntry={true} underlineColorAndroid='transparent'/>
              <TouchableOpacity style={{ height: 40, marginTop: 10 , backgroundColor: '#2E8B57'}} onPress={this._navigate.bind(this)}>
                  <Text style={{color: 'white', textAlign: 'center', marginTop: 10, fontWeight: 'bold'}}>LOGIN</Text>
              </TouchableOpacity>
            </View>
       </View>
     );
  }
}
const styles = StyleSheet.create({
    toolbar: {
     backgroundColor: '#2E8B57',
     height: 40,
     fontFamily: 'noto_serif_regular',
    },
});
AppRegistry.registerComponent('ExampleOne', () => LoginComponent);

second.android.js

import React, { Component } from 'react';
class DashboardComponent extends Component {
  render() {
     return (
       <Text>Hello!</Text>
     );
   }
 }

您在AppRegistry.registerComponent中注册错误的组件,它应该是App,而不是LoginComponent

导航器组件需要首先渲染,然后将导航器支架呈现并传递给IT场景。

相关内容

  • 没有找到相关文章

最新更新