对象不是 react-native 0.49 更新后的构造函数



将 react native 从 0.45.x 更新到 0.50.3 后(并将 index.ios.js重命名为 index.js如图所示(,我在 index.js (以前的 index.ios.js( 中收到此错误:"对象不是构造函数(评估'new _app2.default(('(">

这是我的索引.js文件

import { AppRegistry } from 'react-native';
import App from './app/';
const app = new App();
AppRegistry.registerComponent('airand', () => app);

这是我的应用程序/索引.js文件:

import { Platform, Linking } from 'react-native'
import { Provider } from "react-redux"
import allReducers from "./reducers"
import { Navigation } from 'react-native-navigation'
import RCTSFSafariViewController from 'react-native-sfsafariviewcontroller'
import FontAwesome from 'react-native-vector-icons/FontAwesome'
import registerScreens from './screens/'
import Token from './services/token'
import Api from './services/api'
import configureStore from './store/configureStore'
// import { login, logout } from './reducers/app-root/actions'
import defaultFitlerData from './constants/nearby-cte.js'
const store = configureStore();
registerScreens(store, Provider);
export default class App {
    constructor() {
        this._populateTabBarIcons().then(() => {
            this._startApp();
            this._checkUserLoggedIn();
            store.subscribe(() => this._actionListener());
        });
        // handle linking
        Linking.getInitialURL().then((url) => {
            if (url) {
                this._handleOpenURL(url);
            }
        }).catch((e) => {})
        Linking.addEventListener('url', (event) => this._handleOpenURL(event.url));
    };
    _populateTabBarIcons () {
        return new Promise((resolve, reject) => {
            Promise.all([
                    FontAwesome.getImageSource('map-marker', 30),
                    FontAwesome.getImageSource('map-marker', 30),
                    FontAwesome.getImageSource('ellipsis-h', 30),
                    FontAwesome.getImageSource('ellipsis-h', 30),
                    FontAwesome.getImageSource('plus-square-o', 30),
                    FontAwesome.getImageSource('plus-square', 30),
                    FontAwesome.getImageSource('comment-o', 30),
                    FontAwesome.getImageSource('comment', 30),
                    FontAwesome.getImageSource('user-o', 30),
                    FontAwesome.getImageSource('user', 30)
            ]).then((values) => {
                this.tabBarIcons = [];
                this.selectedTabBarIcons = [];
                for (var i = 0; i < values.length; i += 2) {
                    this.tabBarIcons.push(values[i]);
                    this.selectedTabBarIcons.push(values[i+1]);
                }
                resolve(true);
            }).catch((error) => {
                reject(error);
            }).done();
        });
    };
    componentWillUnmount() {
        // TODO: find a way to call this
        Linking.removeEventListener('url', (event) => this._handleOpenURL(event.url));
    };
    _getParameterByName(name, url) {
        name = name.replace(/[[]]/g, "\$&");
        var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
        if (!results) return null;
        if (!results[2]) return '';
        return decodeURIComponent(results[2].replace(/+/g, " "));
    };
    async _handleOpenURL(url) {
        const pathName = url.split('://')[1].split('?')[0];
        if (pathName.indexOf('login_successful') != -1) {
            const code = this._getParameterByName('code', url);
            if (code) {
                let response = await Api.getTokenFromCode(code);
                if (response.status == 200) {
                    this._checkUserLoggedIn();
                }
            }
        }
        RCTSFSafariViewController.close();
    };
    async _checkUserLoggedIn() {
        let isValid = await Token.isValidRefreshToken();
        if (isValid) {
          this._startApp('logged-in')
        } else {
          this._startApp('logged-out')
        }
    };
    _actionListener() {
        let currentRoot = store.getState().appRoot.root;
        if (currentRoot != lastRoot)
        this._startApp(currentRoot);
    };
    _getTabs() {
        const tabLabel = ['Nearby', 'Pending', 'New', 'Chat', 'Profile'];
        const screens = [
            'airand.NearbyServices',
            'airand.PendingServicesScreen',
            'airand.NewServiceScreen',
            'airand.ChatScreen',
            'airand.Profile'
        ];
        var tabs = [];
        for (var i = 0; i < screens.length; i++) {
            tabs.push({
                icon: this.tabBarIcons[i],
                selectedIcon: this.selectedTabBarIcons[i],
                screen: screens[i]
            });
        };
        return tabs;
    };
    async _startApp(root = null) {
      lastRoot = root
        switch(root) {
            case 'logged-in':
                self.logged_in = true
                Navigation.startTabBasedApp({
                    tabs: this._getTabs(),
                    animationType: 'slide-down',
                    title: 'Redux Example',
                    tabsStyle: {
                        tabBarButtonColor: '#979797',
                        tabBarSelectedButtonColor: '#f79100',
                    }
                });
                return
            case 'logged-out':
                Navigation.startSingleScreenApp({
                    screen: { screen: 'airand.LoginScreen' }
                });
                return
            default:
                Navigation.startSingleScreenApp({
                    screen: { screen: 'airand.LoadingScreen' }
                });
                return
        }
    };
}

这似乎是一个愚蠢的错误,但我花了几个小时,所以请任何帮助将不胜感激,我尝试对应用程序/索引中的几乎所有内容发表一些评论.js但没有运气。

谢谢!

我认为你的问题是这个...

const app = new App();

它告诉你App()不是构造函数。

尝试将{root}/index.js更改为此...

import { AppRegistry } from 'react-native';
import App from './app/';
AppRegistry.registerComponent('airand', () => App);

相关内容

  • 没有找到相关文章