我是React Native的新手,我正在尝试创建一个iOS应用。我的启动屏幕运行良好,并且在创建项目时可以加载初始App.js屏幕。但是,当我将返回值更改为自己的.js文件时,它无法生成,并停留在初始屏幕上。请给我一些提示,我遵循了许多教程。
App.js
// App.js
import React, { Component } from 'react';
import SplashScreen from 'react-native-splash-screen';
import GetStarted from './authentication/GetStarted'
import { createStackNavigator, createAppContainer } from 'react-navigation'
const AuthNav = createAppContainer(
createStackNavigator({
GetStarted: { screen: GetStarted },
})
);
type Props = {};
export default class App extends Component<Props> {
componentDidMount() {
SplashScreen.hide()
}
render() {
return (
<AuthNav />
);
}
}
GetStarted.js
//GetStarted.js
import React, { Component } from 'react';
import {
View,
Text,
StyleSheet,
} from 'react-native';
export default class GetStarted extends Component {
render() {
return (
<View style={styles.container}>
<Text>Lets get started</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItem: 'center',
justifyContent: 'center',
backgroundColor: 'blue'
}
});
package.json
{
"name": "TestApp",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.6.3",
"react-native": "0.58.3",
"react-native-firebase": "^5.2.2",
"react-native-navigation": "^2.12.0",
"react-native-splash-screen": "3.0.6",
"react-navigation": "^3.3.0"
},
"devDependencies": {
"babel-core": "7.0.0-bridge.0",
"babel-jest": "24.0.0",
"jest": "24.0.0",
"metro-react-native-babel-preset": "0.51.1",
"react-test-renderer": "16.6.3"
},
"jest": {
"preset": "react-native"
}
}
答案 0 :(得分:0)
您正在使用"react-navigation": "^3.3.0"
并尝试导入StackNavigator
。他们在v2+
中将StackNavigator
重命名为createStackNavigator
。看来您所使用的教程正在使用v1
。因此,您可以将使用的版本更改为"react-navigation": "^1.5.2"
,也可以保留并使用createStackNavigator
。如果您选择坚持使用的版本(v2+
),请阅读我对同一问题here的另一回复;它将进一步解释。