Browse Source

Expose ReactNativeHost creation in NavigationApplication

This commit also consolidates index files in the playground app
Guy Carmeli 6 years ago
parent
commit
746f240ec5

+ 6
- 1
lib/android/app/src/main/java/com/reactnativenavigation/NavigationApplication.java View File

@@ -6,6 +6,7 @@ import android.support.annotation.Nullable;
6 6
 import com.facebook.react.ReactApplication;
7 7
 import com.facebook.react.ReactNativeHost;
8 8
 import com.facebook.react.ReactPackage;
9
+import com.reactnativenavigation.react.NavigationReactNativeHost;
9 10
 import com.reactnativenavigation.react.ReactGateway;
10 11
 import com.reactnativenavigation.viewcontrollers.externalcomponent.ExternalComponentCreator;
11 12
 
@@ -36,7 +37,11 @@ public abstract class NavigationApplication extends Application implements React
36 37
      * @return a singleton {@link ReactGateway}
37 38
      */
38 39
 	protected ReactGateway createReactGateway() {
39
-	    return new ReactGateway(this, isDebug(), createAdditionalReactPackages());
40
+	    return new ReactGateway(this, isDebug(), createReactNativeHost());
41
+    }
42
+
43
+    protected ReactNativeHost createReactNativeHost() {
44
+        return new NavigationReactNativeHost(this);
40 45
     }
41 46
 
42 47
 	public ReactGateway getReactGateway() {

+ 6
- 3
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationReactNativeHost.java View File

@@ -5,6 +5,7 @@ import android.app.Application;
5 5
 import com.facebook.react.ReactNativeHost;
6 6
 import com.facebook.react.ReactPackage;
7 7
 import com.facebook.react.shell.MainReactPackage;
8
+import com.reactnativenavigation.NavigationApplication;
8 9
 
9 10
 import java.util.ArrayList;
10 11
 import java.util.List;
@@ -18,6 +19,10 @@ public class NavigationReactNativeHost extends ReactNativeHost {
18 19
 	private final boolean isDebug;
19 20
 	private final List<ReactPackage> additionalReactPackages;
20 21
 
22
+    public NavigationReactNativeHost(NavigationApplication application) {
23
+        this(application, application.isDebug(), application.createAdditionalReactPackages());
24
+    }
25
+
21 26
 	public NavigationReactNativeHost(Application application, boolean isDebug, final List<ReactPackage> additionalReactPackages) {
22 27
 		super(application);
23 28
 		this.isDebug = isDebug;
@@ -29,10 +34,8 @@ public class NavigationReactNativeHost extends ReactNativeHost {
29 34
 		return isDebug;
30 35
 	}
31 36
 
32
-	@Override
37
+    @Override
33 38
 	protected List<ReactPackage> getPackages() {
34
-		// Please note that users may provide their own implementations of ReactNativeHost. Any additional
35
-		// package requirements should be documented in the changelog.
36 39
 		List<ReactPackage> packages = new ArrayList<>();
37 40
 		packages.add(new MainReactPackage());
38 41
 		packages.add(new NavigationPackage(this));

+ 12
- 0
playground/android/app/src/main/java/com/reactnativenavigation/playground/MainApplication.java View File

@@ -2,8 +2,10 @@ package com.reactnativenavigation.playground;
2 2
 
3 3
 import android.support.annotation.Nullable;
4 4
 
5
+import com.facebook.react.ReactNativeHost;
5 6
 import com.facebook.react.ReactPackage;
6 7
 import com.reactnativenavigation.NavigationApplication;
8
+import com.reactnativenavigation.react.NavigationReactNativeHost;
7 9
 
8 10
 import java.util.List;
9 11
 
@@ -15,6 +17,16 @@ public class MainApplication extends NavigationApplication {
15 17
         registerExternalComponent("RNNCustomComponent", new FragmentCreator());
16 18
     }
17 19
 
20
+    @Override
21
+    protected ReactNativeHost createReactNativeHost() {
22
+        return new NavigationReactNativeHost(this) {
23
+            @Override
24
+            protected String getJSMainModuleName() {
25
+                return "index";
26
+            }
27
+        };
28
+    }
29
+
18 30
     @Override
19 31
     public boolean isDebug() {
20 32
         return BuildConfig.DEBUG;

+ 0
- 1
playground/index.ios.js View File

@@ -1 +0,0 @@
1
-require('./src/index');

playground/index.android.js → playground/index.js View File


+ 4
- 28
playground/ios/playground/AppDelegate.m View File

@@ -1,45 +1,21 @@
1
-#import "AppDelegate.h"
2
-#import "RNNCustomViewController.h"
3
-
4
-// **********************************************
5
-// *** DON'T MISS: THE NEXT LINE IS IMPORTANT ***
6
-// **********************************************
7 1
 #import <React/RCTBundleURLProvider.h>
8 2
 #import <ReactNativeNavigation/ReactNativeNavigation.h>
9
-
10
-// IMPORTANT: if you're getting an Xcode error that RCCManager.h isn't found, you've probably ran "npm install"
11
-// with npm ver 2. You'll need to "npm install" with npm 3 (see https://github.com/wix/react-native-navigation/issues/1)
12
-
13 3
 #import <React/RCTRootView.h>
14 4
 
5
+#import "AppDelegate.h"
6
+#import "RNNCustomViewController.h"
7
+
15 8
 @implementation AppDelegate
16 9
 
17 10
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
18 11
 {
19
-	// **********************************************
20
-	// *** DON'T MISS: THIS IS HOW WE BOOTSTRAP *****
21
-	// **********************************************
22
-	NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
12
+	NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
23 13
 	[ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions];
24 14
 	
25 15
 	[ReactNativeNavigation registerExternalComponent:@"RNNCustomComponent" callback:^UIViewController *(NSDictionary *props, RCTBridge *bridge) {
26 16
 		return [[RNNCustomViewController alloc] initWithProps:props];
27 17
 	}];
28 18
 	
29
-	/*
30
-	// original RN bootstrap - remove this part
31
-	RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
32
-														moduleName:@"com.example.WelcomeScreen"
33
-												 initialProperties:nil
34
-													 launchOptions:launchOptions];
35
-	self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
36
-	UIViewController *rootViewController = [UIViewController new];
37
-	rootViewController.view = rootView;
38
-	self.window.rootViewController = rootViewController;
39
-	[self.window makeKeyAndVisible];
40
-	*/
41
-	
42
-	
43 19
 	return YES;
44 20
 }
45 21