2017-11-17 39 views
2

更新反應原生從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的一切,但沒有運氣。

謝謝!

回答

0

我覺得你的問題是這樣的......

const app = new App(); 

它告訴你,App()不是一個構造函數。

試着改變你的{root}/index.js這個...

import { AppRegistry } from 'react-native'; 
import App from './app/'; 

AppRegistry.registerComponent('airand',() => App); 
+0

但你可以看到我的應用程序/ index.js不擴展組件,它是啓動應用程序的構造函數。並且它在更新之前可以正常工作。 我仍然嘗試了您所說的,並且出現以下錯誤: 不可違反:元素類型無效:期望字符串(用於內置組件)或類/函數(對於複合組件),但得到:對象.. –

+0

啊,好點!我錯過了。嗯... –

相關問題