createStackNavigation不变违规元素类型无效,预期为字符串

时间:2019-01-21 19:18:00

标签: react-native expo

在创建导入并使用createStackNavigation时,出现以下错误。任何帮助将不胜感激!另外,这是我的第一个本地应用程序,请耐心等待。

我已经尝试过其他版本的StackNavigation来阅读与该错误有关的其他帖子,但这些帖子似乎都无法帮助我。

import React, { Component } from "react";
import { Center } from "@builderx/utils";
import { View, StyleSheet, Image, Text } from "react-native";
import { createAppContainer } from 'react-navigation';
import { MainNavigation } from '../screens/MainNavigator';


const AppContainer = createAppContainer(MainNavigation);

export default class DlLoading_2 extends Component {
  render() {
    return (
      <View style={styles.root}>
        <Center />
        <AppContainer
          TouchableHighlight onPress={() => 
this.navigation.navigate('DlMain')}>
          Image style={styles.blueDisk} source= . 
  {require('../assets/ComponentTMP_0-image.jpg')} />
        </AppContainer>

        <Center horizontal>
          <Image
            source={require("../assets/ComponentTMP_0-image2.png")}
            style={styles.dlLogo}
          />
        </Center>
        <Center horizontal>
          <Text style={styles.text}>TRANSINDENTAL MEDITATION</Text>
        </Center>
      </View>
    );
  }
}
const styles = StyleSheet.create({
  root: {
    backgroundColor: "#FFFFFF",
    flex: 1
  },
  blueDisk: {
    height: 401.5,
    width: 602,
    position: "absolute"
  },
  dlLogo: {
    height: 97,
    width: 300,
    position: "absolute",
    top: "6.61%"
  },
  text: {
    height: 53,
    width: 301,
    top: 660,

    position: "absolute",
    backgroundColor: "transparent",
    lineHeight: 24,
    letterSpacing: 0,
    fontFamily: "Gotham-Book",
    fontSize: 24,
    textAlign: "center",
    color: "rgba(92,92,95,1)"
  }
});

这也是我的MainNavigator.js:

import DlLoading_2 from "./src/screens/DlLoading_2";
import DlMain from "./src/screens/DlMain";
import { createStackNavigator, createAppContainer } from "react- 
navigation";
import { create } from "handlebars";

const MainNavigator = createStackNavigator({
    DlLoading_2: {
      screen: DlLoading_2
    },
    DlMain: {
      screen: DlMain
    }
  },
  {
    headerMode: "none"
  }
  );

  export default createAppContainer(MainNavigator);

2 个答案:

答案 0 :(得分:0)

在DLLoading_2页面

const AppContainer = createAppContainer(MainNavigation);
  • 没有上述代码也可以。
 constructor(props) {
    super(props);

    this.state = {};
  }
  .
  .
  .
this.props.navigation.navigate('DlMain')

 <View style={styles.root}>
        <Center />
  • 这有必要吗?

    MainNavigator.js

const AppContainer = createAppContainer(MainNavigator);

export default AppContainer;

答案 1 :(得分:0)

出现“导出默认值”并使用{}或不使用{} 导入的问题。

更改此行

import { MainNavigation } from '../screens/MainNavigator';

到(去掉大括号)

import  MainNavigation  from '../screens/MainNavigator';