Browse Source

Expose ReactNativeHost creation in NavigationApplication

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

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

6
 import com.facebook.react.ReactApplication;
6
 import com.facebook.react.ReactApplication;
7
 import com.facebook.react.ReactNativeHost;
7
 import com.facebook.react.ReactNativeHost;
8
 import com.facebook.react.ReactPackage;
8
 import com.facebook.react.ReactPackage;
9
+import com.reactnativenavigation.react.NavigationReactNativeHost;
9
 import com.reactnativenavigation.react.ReactGateway;
10
 import com.reactnativenavigation.react.ReactGateway;
10
 import com.reactnativenavigation.viewcontrollers.externalcomponent.ExternalComponentCreator;
11
 import com.reactnativenavigation.viewcontrollers.externalcomponent.ExternalComponentCreator;
11
 
12
 
36
      * @return a singleton {@link ReactGateway}
37
      * @return a singleton {@link ReactGateway}
37
      */
38
      */
38
 	protected ReactGateway createReactGateway() {
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
 	public ReactGateway getReactGateway() {
47
 	public ReactGateway getReactGateway() {

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

5
 import com.facebook.react.ReactNativeHost;
5
 import com.facebook.react.ReactNativeHost;
6
 import com.facebook.react.ReactPackage;
6
 import com.facebook.react.ReactPackage;
7
 import com.facebook.react.shell.MainReactPackage;
7
 import com.facebook.react.shell.MainReactPackage;
8
+import com.reactnativenavigation.NavigationApplication;
8
 
9
 
9
 import java.util.ArrayList;
10
 import java.util.ArrayList;
10
 import java.util.List;
11
 import java.util.List;
18
 	private final boolean isDebug;
19
 	private final boolean isDebug;
19
 	private final List<ReactPackage> additionalReactPackages;
20
 	private final List<ReactPackage> additionalReactPackages;
20
 
21
 
22
+    public NavigationReactNativeHost(NavigationApplication application) {
23
+        this(application, application.isDebug(), application.createAdditionalReactPackages());
24
+    }
25
+
21
 	public NavigationReactNativeHost(Application application, boolean isDebug, final List<ReactPackage> additionalReactPackages) {
26
 	public NavigationReactNativeHost(Application application, boolean isDebug, final List<ReactPackage> additionalReactPackages) {
22
 		super(application);
27
 		super(application);
23
 		this.isDebug = isDebug;
28
 		this.isDebug = isDebug;
29
 		return isDebug;
34
 		return isDebug;
30
 	}
35
 	}
31
 
36
 
32
-	@Override
37
+    @Override
33
 	protected List<ReactPackage> getPackages() {
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
 		List<ReactPackage> packages = new ArrayList<>();
39
 		List<ReactPackage> packages = new ArrayList<>();
37
 		packages.add(new MainReactPackage());
40
 		packages.add(new MainReactPackage());
38
 		packages.add(new NavigationPackage(this));
41
 		packages.add(new NavigationPackage(this));

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

2
 
2
 
3
 import android.support.annotation.Nullable;
3
 import android.support.annotation.Nullable;
4
 
4
 
5
+import com.facebook.react.ReactNativeHost;
5
 import com.facebook.react.ReactPackage;
6
 import com.facebook.react.ReactPackage;
6
 import com.reactnativenavigation.NavigationApplication;
7
 import com.reactnativenavigation.NavigationApplication;
8
+import com.reactnativenavigation.react.NavigationReactNativeHost;
7
 
9
 
8
 import java.util.List;
10
 import java.util.List;
9
 
11
 
15
         registerExternalComponent("RNNCustomComponent", new FragmentCreator());
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
     @Override
30
     @Override
19
     public boolean isDebug() {
31
     public boolean isDebug() {
20
         return BuildConfig.DEBUG;
32
         return BuildConfig.DEBUG;

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

1
-require('./src/index');

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


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

1
-#import "AppDelegate.h"
2
-#import "RNNCustomViewController.h"
3
-
4
-// **********************************************
5
-// *** DON'T MISS: THE NEXT LINE IS IMPORTANT ***
6
-// **********************************************
7
 #import <React/RCTBundleURLProvider.h>
1
 #import <React/RCTBundleURLProvider.h>
8
 #import <ReactNativeNavigation/ReactNativeNavigation.h>
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
 #import <React/RCTRootView.h>
3
 #import <React/RCTRootView.h>
14
 
4
 
5
+#import "AppDelegate.h"
6
+#import "RNNCustomViewController.h"
7
+
15
 @implementation AppDelegate
8
 @implementation AppDelegate
16
 
9
 
17
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
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
 	[ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions];
13
 	[ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions];
24
 	
14
 	
25
 	[ReactNativeNavigation registerExternalComponent:@"RNNCustomComponent" callback:^UIViewController *(NSDictionary *props, RCTBridge *bridge) {
15
 	[ReactNativeNavigation registerExternalComponent:@"RNNCustomComponent" callback:^UIViewController *(NSDictionary *props, RCTBridge *bridge) {
26
 		return [[RNNCustomViewController alloc] initWithProps:props];
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
 	return YES;
19
 	return YES;
44
 }
20
 }
45
 
21