0

尝试呈现 NavigatorIOS 组件时出现错误。当尝试使用简单的视图和文本时,它工作得很好。但是对于 NavigatorIOS,它给出了一个错误。

import React, {Component} from 'react';

const LandingPage = require('./layouts/landing_page/LandingPage');
const I18n = require('react-native-i18n');
const AsyncStorageHelper = require('./ios_commons/helper/AsyncStorageHelper');
const moment = require('moment');
var TranslationProperty = require('./properties/TranslationProperties.json');

import {StyleSheet, StatusBar, NavigatorIOS} from 'react-native';

export default class App extends Component<{}> {
    constructor(props) {
        super(props);
        this.state = {};
        I18n.fallbacks = true;
        I18n.translations = require('./ios_commons/Strings');
        // Text.defaultProps.allowFontScaling = false;
        StatusBar.setBarStyle('light-content', true);
        this.loadAppSpecificLanguage();
    }

    loadAppSpecificLanguage = () => {
        AsyncStorageHelper.getAppSpecificLanguage()
            .then(item => {
                if (item !== null) {
                    console.log('Found app specific locale ' + item);
                    let userDefinedLocale = JSON.parse(item).code;
                    I18n.locale = userDefinedLocale;
                    moment.locale(userDefinedLocale);
                } else {
                    console.log('App specific language property not found');
                    let defaultLocale = TranslationProperty.slice()[0];
                    if (defaultLocale === null || defaultLocale === undefined) {
                        console.log(
                            'LOCALIZATION WARNING: Couldn\'t find default locale. Setting to locale \'en\'',
                        );
                        I18n.locale = 'en';
                        moment.locale('en');
                    } else {
                        console.log('Setting default locale ' + defaultLocale.code);
                        moment.locale(defaultLocale.code);
                        AsyncStorageHelper.saveAppSpecificLanguage(defaultLocale);
                    }
                }
            })
            .catch(error => {
                console.log('Failed to obtain app specific language ' + error);
            });
    };

    render() {
        return (
            <NavigatorIOS
                style={styles.navigationContainer}
                ref="nav"
                initialRoute={{
                    title: 'LandingPage',
                    component: LandingPage,
                }}
                navigationBarHidden={true}
            />
        );
    }
}

const styles = StyleSheet.create({
    navigationContainer: {
        flex: 1,
    },
});

我看到的错误如下:

未处理的 JS 异常:错误:元素类型无效:需要字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义。您可能忘记从定义组件的文件中导出组件,或者您可能混淆了默认导入和命名导入。

检查App.

此错误位于: AppContainer 中(renderApplication.js:45)中 RCTView(AppContainer.js:109)中 RCTView(AppContainer.js:135)中 AppContainer(renderApplication.js:39)

这是什么原因造成的?如何解决这个问题?

4

0 回答 0