|
@@ -2,17 +2,23 @@ package com.reactnativenavigation.react;
|
2
|
2
|
|
3
|
3
|
import com.facebook.react.ReactInstanceManager;
|
4
|
4
|
import com.facebook.react.bridge.ReactContext;
|
|
5
|
+import com.facebook.react.devsupport.interfaces.PackagerStatusCallback;
|
5
|
6
|
import com.reactnativenavigation.NavigationActivity;
|
|
7
|
+import com.reactnativenavigation.utils.Toaster;
|
|
8
|
+import com.reactnativenavigation.utils.UiThread;
|
6
|
9
|
|
7
|
10
|
public class NavigationReactInitializer implements ReactInstanceManager.ReactInstanceEventListener {
|
8
|
11
|
|
9
|
12
|
private final ReactInstanceManager reactInstanceManager;
|
10
|
13
|
private final DevPermissionRequest devPermissionRequest;
|
|
14
|
+ private final boolean isDebug;
|
11
|
15
|
private boolean waitingForAppLaunchEvent = true;
|
|
16
|
+ private boolean isPackagerRunning = false;
|
12
|
17
|
|
13
|
18
|
public NavigationReactInitializer(ReactInstanceManager reactInstanceManager, boolean isDebug) {
|
14
|
19
|
this.reactInstanceManager = reactInstanceManager;
|
15
|
20
|
this.devPermissionRequest = new DevPermissionRequest(isDebug);
|
|
21
|
+ this.isDebug = isDebug;
|
16
|
22
|
}
|
17
|
23
|
|
18
|
24
|
public void onActivityCreated(NavigationActivity activity) {
|
|
@@ -42,6 +48,25 @@ public class NavigationReactInitializer implements ReactInstanceManager.ReactIns
|
42
|
48
|
}
|
43
|
49
|
|
44
|
50
|
private void prepareReactApp() {
|
|
51
|
+ if (isDebug && !isPackagerRunning) {
|
|
52
|
+ reactInstanceManager.getDevSupportManager().isPackagerRunning(new PackagerStatusCallback() {
|
|
53
|
+ @Override
|
|
54
|
+ public void onPackagerStatusFetched(final boolean packagerIsRunning) {
|
|
55
|
+ UiThread.post(new Runnable() {
|
|
56
|
+ @Override
|
|
57
|
+ public void run() {
|
|
58
|
+ isPackagerRunning = packagerIsRunning;
|
|
59
|
+ if (!isPackagerRunning) {
|
|
60
|
+ Toaster.toast("Packager is not running!");
|
|
61
|
+ } else {
|
|
62
|
+ prepareReactApp();
|
|
63
|
+ }
|
|
64
|
+ }
|
|
65
|
+ });
|
|
66
|
+ }
|
|
67
|
+ });
|
|
68
|
+ return;
|
|
69
|
+ }
|
45
|
70
|
reactInstanceManager.addReactInstanceEventListener(this);
|
46
|
71
|
if (shouldCreateContext()) {
|
47
|
72
|
reactInstanceManager.createReactContextInBackground();
|