我的初始屏幕不会移动到 react 本机上的下一个屏幕



我是React Native的新手,我正在尝试创建一个iOS应用程序。我的Splash屏幕正常工作,并在创建Project Fim时加载初始app.js屏幕。但是,当我将返回到自己的.js文件时,它将无法构建,并且被卡在Splash屏幕上。请给我一些提示,我遵循了许多教程。

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"
}
}

您正在使用"react-navigation": "^3.3.0"并尝试导入StackNavigator。在v2+中,他们将StackNavigator重命名为createStackNavigator。看起来您使用的教程是使用v1。因此,您可以将使用的版本更改为"react-navigation": "^1.5.2",也可以使用createStackNavigator。如果您选择坚持使用的版本(v2+),请在此处阅读我对同一问题的另一个回答;它将进一步解释。

相关内容

  • 没有找到相关文章

最新更新