0

我有标题中描述的问题。我运行调试器,它只到达 index.js 而不是 index.ios.js,因为它甚至不存在于调试器中。所以它应该是一个 react-native-navigation 问题。它卡在启动画面中,应用名称显示 Powered by react native。日志没有显示任何错误,只是随机警告。

我的 AppDelegate.m 是:

#import "AppDelegate.h"
#import <React/RCTBundleURLProvider.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>

// **********************************************
// *** DON'T MISS: THE NEXT LINE IS IMPORTANT ***
// **********************************************
#import <TwitterKit/TwitterKit.h>

// IMPORTANT: if you're getting an Xcode error that RCCManager.h isn't found, you've probably ran "npm install"
// with npm ver 2. You'll need to "npm install" with npm 3 (see https://github.com/wix/react-native-navigation/issues/1)

#import <Firebase.h>
#import "RCCManager.h"

#import <React/RCTRootView.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [FIRApp configure];

  [[FBSDKApplicationDelegate sharedInstance] application:application
                           didFinishLaunchingWithOptions:launchOptions];


  NSURL *jsCodeLocation;
#ifdef DEBUG
  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  self.window.backgroundColor = [UIColor whiteColor];
  [[RCCManager sharedInstance] initBridgeWithBundleURL:jsCodeLocation launchOptions:launchOptions];

  return YES;
}

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
            options:(NSDictionary<NSString *,id> *)options {

  BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application
                                                                openURL:url
                                                      sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
                                                             annotation:options[UIApplicationOpenURLOptionsAnnotationKey]
                  ];

  BOOL handledT = [[Twitter sharedInstance] application:application openURL:url options:options];
  // Add any custom logic here.
  return handled || handledT;
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
  [FBSDKAppEvents activateApp];
}

@end

我的 index.js(调试器到达这个文件)

import React from 'react';
import { AppRegistry } from 'react-native';
import { Provider } from 'react-redux';
import App from './App';
import configureStore from './src/store/configureStore';

const store = configureStore();


const RNRedux = () => (
    <Provider store={store}>
        <App />
    </Provider>
);

AppRegistry.registerComponent('myapp', () => RNRedux);

index.ios.js (android 一个和这个一样,它可以工作,调试器没有到达这个文件)

import App from './App';

App();

应用文件:

import { Navigation } from "react-native-navigation";
import { Provider } from "react-redux";

import configureStore from "./src/store/configureStore";

import startMainTabs from "./src/screens/MainTabs/startMainTabs";

import AuthScreen from "./src/screens/Auth/Auth";

import MainScreen from "./src/screens/Main/Main";


const store = configureStore();

// Register Screens
Navigation.registerComponent(
  "AuthScreen",
  () => AuthScreen,
  store,
  Provider
);


Navigation.registerComponent(
  "MainScreen",
  () => MainScreen,
  store,
  Provider
);





// Start a App
export default () => startMainTabs();

还有我的 startMainTabs 文件:

import { Navigation } from 'react-native-navigation';
import { Platform } from 'react-native';
import Icon from 'react-native-vector-icons/Ionicons';
import LanguagesManager from '../../../config/LanguagesManager';


const startTabs = () => {

    const language = new LanguagesManager("es");


    Promise.all([
        Icon.getImageSource(Platform.OS === 'android' ? "md-map" : "ios-map", 30),
        Icon.getImageSource(Platform.OS === 'android' ? "md-share-alt" : "ios-share", 30),
        Icon.getImageSource(Platform.OS === 'android' ? "md-menu" : "ios-menu", 30)
    ]).then(sources => {
        Navigation.startTabBasedApp({
            tabs: [
                {   
                    screen: "MainScreen",
                    label: language.causes_explorer_title,
                    title: language.causes_explorer_label,
                    icon: sources[0],
                    navigatorButtons: {
                        leftButtons: [
                            {
                                icon: sources[2],
                                title: language.sidedrawer_title,
                                id: "sideDrawerToggle"
                            }
                        ]
                    }
                }
            ],
            tabsStyle: {
                tabBarSelectedButtonColor: "orange"
            },
            drawer: {
                left: {
                    screen: "SideDrawer"
                }
            },
            appStyle: {
                orientation: 'portrait',
                tabBarSelectedButtonColor: "orange"
            },
            animationType: 'slide-down'
         });
    });
};

export default startTabs;

我在 package.json 文件中的依赖项:

"dependencies": {
    "axios": "^0.18.0",
    "lodash": "^4.17.5",
    "native-base": "^2.4.1",
    "react": "16.3.1",
    "react-native": "0.54.1",
    "react-native-app-intro-slider": "^0.2.4",
    "react-native-datepicker": "^1.7.1",
    "react-native-fbsdk": "^0.7.0",
    "react-native-firebase": "^4.0.0",
    "react-native-image-picker": "^0.26.7",
    "react-native-navigation": "^1.1.435",
    "react-native-twitter-signin": "^1.0.2",
    "react-native-vector-icons": "^4.4.2",
    "react-redux": "^5.0.6",
    "redux": "^3.7.2",
    "redux-thunk": "^2.2.0"
  }

有谁知道如何解决这一问题?非常感谢您的帮助!

4

1 回答 1

0

问题出在 App.js 文件的导出上。我更改了 export default () => startMainTabs(); 开始MainTabs(); 并且它起作用了,因为它没有执行 index.ios.js 文件,因此该文件没有对这个新更改做任何事情。至于 android,我也只是将文件留空,因为使用此设置,它将始终通过 index.js

于 2018-04-22T04:59:02.583 回答