|
@@ -1,15 +1,42 @@
|
1
|
1
|
package com.reactnativenavigation.react;
|
2
|
2
|
|
|
3
|
+import com.facebook.react.devsupport.DevSupportManager;
|
|
4
|
+import com.facebook.react.devsupport.DevSupportManagerImpl;
|
|
5
|
+import com.facebook.react.devsupport.ReactInstanceDevCommandsHandler;
|
|
6
|
+import com.facebook.react.devsupport.RedBoxHandler;
|
3
|
7
|
import com.reactnativenavigation.NavigationActivity;
|
4
|
8
|
import com.reactnativenavigation.NavigationApplication;
|
|
9
|
+import com.reactnativenavigation.utils.ReflectionUtils;
|
5
|
10
|
|
6
|
11
|
public class ReactGateway {
|
|
12
|
+
|
|
13
|
+ public interface JsReloadListener {
|
|
14
|
+ void onJsReload();
|
|
15
|
+ }
|
|
16
|
+
|
7
|
17
|
private final NavigationReactNativeHost reactNativeHost;
|
8
|
18
|
private final NavigationReactInitializer initializer;
|
9
|
19
|
private final JsDevReloadHandler jsDevReloadHandler;
|
10
|
20
|
|
11
|
21
|
public ReactGateway(final NavigationApplication application, final boolean isDebug) {
|
12
|
22
|
reactNativeHost = new NavigationReactNativeHost(application, isDebug);
|
|
23
|
+
|
|
24
|
+ DevSupportManager devSupportManager = reactNativeHost.getReactInstanceManager().getDevSupportManager();
|
|
25
|
+ ReactInstanceDevCommandsHandler reactInstanceCommandsHandler = (ReactInstanceDevCommandsHandler) ReflectionUtils.getDeclaredField(devSupportManager, "mReactInstanceCommandsHandler");
|
|
26
|
+ String packagerPathForJsBundle = reactNativeHost.getJSMainModuleName();
|
|
27
|
+ boolean enableOnCreate = reactNativeHost.getUseDeveloperSupport();
|
|
28
|
+ RedBoxHandler redBoxHandler = reactNativeHost.getRedBoxHandler();
|
|
29
|
+ DevSupportManagerImpl proxy = new DevSupportManagerImpl(application, reactInstanceCommandsHandler, packagerPathForJsBundle, enableOnCreate, redBoxHandler) {
|
|
30
|
+ @Override
|
|
31
|
+ public void handleReloadJS() {
|
|
32
|
+ super.handleReloadJS();
|
|
33
|
+ // onJsReload
|
|
34
|
+// ReactContext currentReactContext = reactNativeHost.getReactInstanceManager().getCurrentReactContext();
|
|
35
|
+// ((NavigationActivity) currentReactContext.getCurrentActivity()).getNavigator().onDestroy();
|
|
36
|
+ }
|
|
37
|
+ };
|
|
38
|
+ ReflectionUtils.setField(reactNativeHost.getReactInstanceManager(), "mDevSupportManager", proxy);
|
|
39
|
+
|
13
|
40
|
initializer = new NavigationReactInitializer(reactNativeHost.getReactInstanceManager(), isDebug);
|
14
|
41
|
jsDevReloadHandler = new JsDevReloadHandler(reactNativeHost.getReactInstanceManager());
|
15
|
42
|
}
|