对象不是反应原生后的构造函数0.49更新
问题描述:
更新反应原生从0.45.x到0.50.3(并按照指示将index.ios.js重命名为index.js),我在index.js(以前index.ios.js): “对象不是(评估 '新_app2.default()')构造”对象不是反应原生后的构造函数0.49更新
这里是我的index.js文件
import { AppRegistry } from 'react-native';
import App from './app/';
const app = new App();
AppRegistry.registerComponent('airand',() => app);
这里是我的应用程序/index.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
}
};
}
这似乎是一个愚蠢的错误,但我已经花了几个小时,所以请任何帮助,将不胜感激,我已经尝试评论一些东西几乎在app/index.js的一切,但没有运气。
谢谢!
答
我觉得你的问题是这样的......
const app = new App();
它告诉你,App()
不是一个构造函数。
试着改变你的{root}/index.js
这个...
import { AppRegistry } from 'react-native';
import App from './app/';
AppRegistry.registerComponent('airand',() => App);
但你可以看到我的应用程序/ index.js不扩展组件,它是启动应用程序的构造函数。并且它在更新之前可以正常工作。 我仍然尝试了您所说的,并且出现以下错误: 不可违反:元素类型无效:期望字符串(用于内置组件)或类/函数(对于复合组件),但得到:对象.. –
啊,好点!我错过了。嗯... –