应用程序停留在Splash屏幕反应原生导航

时间:2017-10-17 12:57:10

标签: ios react-native react-native-navigation

我根据react-native-navigation上的示例更改了AppDelegate.m文件。我将index.ios更改为index,因为本机生成器不再生成index.ios文件。

jsCodeLocation =[[RCTBundleURLProvidersharedSettings]jsBundleURLForBundleRoot:@"index" fallbackResource:nil];

#import "AppDelegate.h"
#import <React/RCTBundleURLProvider.h>
#import "RCCManager.h"
#import <React/RCTRootView.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)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;
}
@end

现在,应用程序停留在启动屏幕上,该屏幕显示项目名称,并显示在以下版本的Powered by react native。

function onPressLearnMore() {

  Navigation.startSingleScreenApp({
    screen: {
      screen: 'app.screens.HomeScreen', // unique ID registered with Navigation.registerScreen
      title: 'Welcome', // title of the screen as appears in the nav bar (optional)
      navigatorStyle: {}, // override the navigator style for the screen, see "Styling the navigator" below (optional)
      navigatorButtons: {} // override the nav buttons for the screen, see "Adding buttons to the navigator" below (optional)
    },
    passProps: {}, // simple serializable object that will pass as props to all top screens (optional)
    animationType: 'slide-down' // optional, add transition animation to root change: 'none', 'slide-down', 'fade'
  });
  console.log("Hello");
}

环境

react-native-cli: 2.0.1
react-native: 0.49.3

1 个答案:

答案 0 :(得分:0)

您似乎正在尝试从处理程序启动应用程序。 您在RN 0.49的右侧有一个入口点,因此您应该从startSingleScreenApp拨打index.js,因此您的索引应该与此类似:

import {Navigation} from 'react-native-navigation';
import {registerScreens} from './screens';

registerScreens();
Navigation.startSingleScreenApp({
screen: {
  screen: 'app.screens.HomeScreen', // unique ID registered with Navigation.registerScreen
  title: 'Welcome', // title of the screen as appears in the nav bar (optional)
  navigatorStyle: {}, // override the navigator style for the screen, see "Styling the navigator" below (optional)
  navigatorButtons: {} // override the nav buttons for the screen, see "Adding buttons to the navigator" below (optional)
},
passProps: {}, // simple serializable object that will pass as props to all top screens (optional)
animationType: 'slide-down' // optional, add transition animation to root change: 'none', 'slide-down', 'fade'});