Bläddra i källkod

Exposed getUiImplementationProvider for people to override if needed (#3295)

Ioannis Kokkinidis 6 år sedan
förälder
incheckning
7a0bc3f8bd

+ 7
- 1
android/app/src/main/java/com/reactnativenavigation/NavigationApplication.java Visa fil

@@ -12,6 +12,7 @@ import com.facebook.react.ReactApplication;
12 12
 import com.facebook.react.ReactNativeHost;
13 13
 import com.facebook.react.ReactPackage;
14 14
 import com.facebook.react.bridge.ReactContext;
15
+import com.facebook.react.uimanager.UIImplementationProvider;
15 16
 import com.facebook.react.uimanager.UIManagerModule;
16 17
 import com.reactnativenavigation.bridge.EventEmitter;
17 18
 import com.reactnativenavigation.controllers.ActivityCallbacks;
@@ -34,7 +35,7 @@ public abstract class NavigationApplication extends Application implements React
34 35
         super.onCreate();
35 36
         instance = this;
36 37
         handler = new Handler(getMainLooper());
37
-        reactGateway = new NavigationReactGateway();
38
+        reactGateway = new NavigationReactGateway(getUIImplementationProvider());
38 39
         eventEmitter = new EventEmitter(reactGateway);
39 40
         activityCallbacks = new ActivityCallbacks();
40 41
     }
@@ -53,6 +54,11 @@ public abstract class NavigationApplication extends Application implements React
53 54
         }
54 55
     }
55 56
 
57
+    // here in case someone wants to override this
58
+    protected UIImplementationProvider getUIImplementationProvider() {
59
+        return null; // if null the default UIImplementationProvider will be used
60
+    }
61
+
56 62
     public void startReactContextOnceInBackgroundAndExecuteJS() {
57 63
         reactGateway.startReactContextOnceInBackgroundAndExecuteJS();
58 64
     }

+ 28
- 3
android/app/src/main/java/com/reactnativenavigation/react/NavigationReactGateway.java Visa fil

@@ -10,6 +10,7 @@ import com.facebook.react.ReactPackage;
10 10
 import com.facebook.react.bridge.ReactContext;
11 11
 import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
12 12
 import com.facebook.react.shell.MainReactPackage;
13
+import com.facebook.react.uimanager.UIImplementationProvider;
13 14
 import com.reactnativenavigation.NavigationApplication;
14 15
 import com.reactnativenavigation.bridge.NavigationReactEventEmitter;
15 16
 import com.reactnativenavigation.bridge.NavigationReactPackage;
@@ -28,7 +29,28 @@ public class NavigationReactGateway implements ReactGateway {
28 29
 	private JsDevReloadHandler jsDevReloadHandler;
29 30
 
30 31
 	public NavigationReactGateway() {
31
-		host = new ReactNativeHostImpl();
32
+		this(null);
33
+	}
34
+
35
+	public NavigationReactGateway(final UIImplementationProvider customImplProvider) {
36
+
37
+		if (customImplProvider != null) {
38
+			host = new ReactNativeHostImpl() {
39
+				/**
40
+				 * This was added in case someone needs to provide a different UIImplementationProvider
41
+				 * @param {UIImplementationProvider} defaultProvider
42
+				 * @return {UIImplementationProvider}
43
+				 */
44
+				@Override
45
+				protected UIImplementationProvider getUIImplementationProvider() {
46
+					return customImplProvider;
47
+				}
48
+			};
49
+		} else {
50
+			host = new ReactNativeHostImpl();
51
+		}
52
+
53
+
32 54
 		jsDevReloadHandler = new JsDevReloadHandler();
33 55
 	}
34 56
 
@@ -41,6 +63,7 @@ public class NavigationReactGateway implements ReactGateway {
41 63
 		return host.hasInstance() && getReactInstanceManager().getCurrentReactContext() != null;
42 64
 	}
43 65
 
66
+
44 67
 	@Override
45 68
 	public boolean hasStartedCreatingContext() {
46 69
 		return getReactInstanceManager().hasStartedCreatingInitialContext();
@@ -105,6 +128,7 @@ public class NavigationReactGateway implements ReactGateway {
105 128
 		}
106 129
 	}
107 130
 
131
+
108 132
 	public ReactNativeHost getReactNativeHost() {
109 133
 		return host;
110 134
 	}
@@ -114,12 +138,13 @@ public class NavigationReactGateway implements ReactGateway {
114 138
 		reactEventEmitter = new NavigationReactEventEmitter(context);
115 139
 	}
116 140
 
117
-	private static class ReactNativeHostImpl extends ReactNativeHost implements ReactInstanceManager.ReactInstanceEventListener {
141
+	public static class ReactNativeHostImpl extends ReactNativeHost implements ReactInstanceManager.ReactInstanceEventListener {
118 142
 
119
-		ReactNativeHostImpl() {
143
+		public ReactNativeHostImpl() {
120 144
 			super(NavigationApplication.instance);
121 145
 		}
122 146
 
147
+
123 148
 		@Override
124 149
 		public boolean getUseDeveloperSupport() {
125 150
 			return NavigationApplication.instance.isDebug();