无法确定错误的来源;元素类型无效:应为字符串

时间:2021-02-04 08:55:18

标签: javascript react-native

我的应用程序屏幕。 js返回

<块引用>

[未处理的承诺拒绝:错误:元素类型无效:预期 一个字符串(对于内置组件)或一个类/函数(对于复合 组件)但得到:未定义。您可能忘记导出您的 来自它定义的文件的组件,或者你可能混淆了 默认和命名导入。]

错误没有给我除了'render method'之外的问题的位置你能看到错误在哪里吗,你能帮我找到问题的根源吗? 非常感谢

import Splash from './src/components/Splash';
import React from "react";
import {
  View,
  Text,
  StatusBar,
  Image,
  ActivityIndicator,
} from "react-native";
import MainStackNavigator from "./Navigation/StackNavigator";
import styles from "./assets/styles";
import {
  retrieveAppLang,
  userSessionActive
} from "./src/common/Preferences";
import i18n from "./src/i18n";

export default class App extends React.Component {
  constructor(props) {
    super(props);
    Text.defaultProps = Text.defaultProps || {};
    Text.defaultProps.allowFontScaling = false; 
    this.state = {
      isFirstConnection: true,
      status: 0,

    };
  }

  async UNSAFE_componentWillMount() {
    let lang = await retrieveAppLang();
    let isConnected = await userSessionActive();

    if (lang.length == 2) {
      i18n.changeLanguage(lang);
    }

    if (isConnected === true && this.props && this.props.navigation) {
      this.props.navigation.navigate("BottomTabNavigator");
    }
  }

  async componentDidMount() {
   
    const data = await this.performTimeConsumingTask();
    if (data !== null) {
      this.setState({
        isFirstConnection: false,
        status: 1,
      });
    }
  }

  performTimeConsumingTask = async () => {
    return new Promise((resolve) =>
      setTimeout(() => {
        resolve("result");
      }, 750)
    );
  };

  render() {
    if (this.state.status == 1) {
      if (this.state.isFirstConnection) {
        return <Splash />;
      } else {
        return <MainStackNavigator screenProps={'Authentication'} />;
      }
    }

    return (
        <View style={[styles.container, styles.containerCentered]}>
          <StatusBar hidden={true} />
          <View style={styles.subContainer}>
            <Image
              style={styles.logo}
              source={require("./assets/images/logo.png")}
            />
            <ActivityIndicator size="large" color="#43300E" />
            <Text>{i18n.t("app.loading") + "..."}</Text>
          </View>
        </View>
    );
  }
}

0 个答案:

没有答案