|
@@ -4,7 +4,6 @@ import com.facebook.react.ReactInstanceManager;
|
4
|
4
|
import com.facebook.react.bridge.ReactContext;
|
5
|
5
|
import com.facebook.react.devsupport.interfaces.PackagerStatusCallback;
|
6
|
6
|
import com.reactnativenavigation.NavigationActivity;
|
7
|
|
-import com.reactnativenavigation.utils.Toaster;
|
8
|
7
|
import com.reactnativenavigation.utils.UiThread;
|
9
|
8
|
|
10
|
9
|
public class NavigationReactInitializer implements ReactInstanceManager.ReactInstanceEventListener {
|
|
@@ -13,7 +12,6 @@ public class NavigationReactInitializer implements ReactInstanceManager.ReactIns
|
13
|
12
|
private final DevPermissionRequest devPermissionRequest;
|
14
|
13
|
private final boolean isDebug;
|
15
|
14
|
private boolean waitingForAppLaunchEvent = true;
|
16
|
|
- private boolean isPackagerRunning = false;
|
17
|
15
|
|
18
|
16
|
public NavigationReactInitializer(ReactInstanceManager reactInstanceManager, boolean isDebug) {
|
19
|
17
|
this.reactInstanceManager = reactInstanceManager;
|
|
@@ -30,7 +28,7 @@ public class NavigationReactInitializer implements ReactInstanceManager.ReactIns
|
30
|
28
|
devPermissionRequest.askPermission(activity);
|
31
|
29
|
} else {
|
32
|
30
|
reactInstanceManager.onHostResume(activity, activity);
|
33
|
|
- prepareReactApp();
|
|
31
|
+ checkBundleThenPrepareReact(activity);
|
34
|
32
|
}
|
35
|
33
|
}
|
36
|
34
|
|
|
@@ -47,26 +45,30 @@ public class NavigationReactInitializer implements ReactInstanceManager.ReactIns
|
47
|
45
|
}
|
48
|
46
|
}
|
49
|
47
|
|
50
|
|
- private void prepareReactApp() {
|
51
|
|
- if (isDebug && !isPackagerRunning) {
|
|
48
|
+ private void checkBundleThenPrepareReact(final NavigationActivity activity) {
|
|
49
|
+ if (isDebug) {
|
52
|
50
|
reactInstanceManager.getDevSupportManager().isPackagerRunning(new PackagerStatusCallback() {
|
53
|
51
|
@Override
|
54
|
52
|
public void onPackagerStatusFetched(final boolean packagerIsRunning) {
|
55
|
53
|
UiThread.post(new Runnable() {
|
56
|
54
|
@Override
|
57
|
55
|
public void run() {
|
58
|
|
- isPackagerRunning = packagerIsRunning;
|
59
|
|
- if (!isPackagerRunning) {
|
60
|
|
- Toaster.toast("Packager is not running!");
|
|
56
|
+ if (!packagerIsRunning) {
|
|
57
|
+ activity.toast("Packager is not running!");
|
|
58
|
+ activity.finish();
|
61
|
59
|
} else {
|
62
|
|
- prepareReactApp();
|
|
60
|
+ prepareReactAppWithWorkingBundle();
|
63
|
61
|
}
|
64
|
62
|
}
|
65
|
63
|
});
|
66
|
64
|
}
|
67
|
65
|
});
|
68
|
|
- return;
|
|
66
|
+ } else {
|
|
67
|
+ prepareReactAppWithWorkingBundle();
|
69
|
68
|
}
|
|
69
|
+ }
|
|
70
|
+
|
|
71
|
+ private void prepareReactAppWithWorkingBundle() {
|
70
|
72
|
reactInstanceManager.addReactInstanceEventListener(this);
|
71
|
73
|
if (shouldCreateContext()) {
|
72
|
74
|
reactInstanceManager.createReactContextInBackground();
|