两个错误:
-
你不应该打电话
AppRegistry
app.js
-
你是怎么误解的
react-navigation
StackNavigator
(以及Tab和Drawer)是需要直接渲染的组件(例如,您传递给的内容)
[A] )或在应用程序中的某个时刻[B]。
所以要解决这个问题,您需要导出
myscreens
App
. 为了说明这两种方法:
A.
in the docs
,但由于您将代码分解为两个文件,因此它看起来是这样的:
./组件/应用程序。js公司
import React, { Component } from 'react';
import { StackNavigator } from 'react-navigation';
import { Text, View } from 'react-native';
class App extends Component {
static navigationOptions = {
title: 'Login',
headerStyle: {
backgroundColor: '#000000',
},
headerTitleStyle: {
color: '#fff',
},
};
constructor(props) {
super(props);
}
render() {
console.log(this.props);
const { navigate } = this.props.navigation;
return (
<View>
<Text>Hello</Text>
</View>
);
}
}
const myscreens = StackNavigator({
Home: { screen: App },
});
export default myscreens;
指数安卓js公司
import { AppRegistry } from 'react-native';
import myscreens from './components/app';
AppRegistry.registerComponent('myapp', () => myscreens);
您将渲染
堆栈导航器
然后导出呈现它的类。这更符合您已经在做的事情,从长远来看更灵活(例如:如果您使用
redux
./组件/应用程序。js公司
myscreens公司
MyScreens
complain about this
像
lowercase JSX tags are considered to be HTML
. 使用
myscreens公司
在JSX中。
import React, { Component } from 'react';
import { StackNavigator } from 'react-navigation';
import { Text, View } from 'react-native';
class App extends Component {
static navigationOptions = {
title: 'Login',
headerStyle: {
backgroundColor: '#000000',
},
headerTitleStyle: {
color: '#fff',
},
};
constructor(props) {
super(props);
}
render() {
console.log(this.props);
const { navigate } = this.props.navigation;
return (
<View>
<Text>Hello</Text>
</View>
);
}
}
const MyScreens = StackNavigator({
Home: { screen: App },
});
export default MyScreens;
import React, { Component } from 'react';
import { AppRegistry } from 'react-native';
import MyScreens from './components/app';
export default class myapp extends Component {
render() {
return <MyScreens />;
}
}
AppRegistry.registerComponent('myapp', () => myapp);