|
@@ -2,24 +2,20 @@ 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;
|
6
|
5
|
import com.reactnativenavigation.NavigationActivity;
|
7
|
|
-import com.reactnativenavigation.utils.UiThread;
|
8
|
6
|
|
9
|
7
|
public class NavigationReactInitializer implements ReactInstanceManager.ReactInstanceEventListener {
|
10
|
8
|
|
11
|
9
|
private final ReactInstanceManager reactInstanceManager;
|
12
|
10
|
private final DevPermissionRequest devPermissionRequest;
|
13
|
|
- private final boolean isDebug;
|
14
|
11
|
private boolean waitingForAppLaunchEvent = true;
|
15
|
12
|
|
16
|
13
|
public NavigationReactInitializer(ReactInstanceManager reactInstanceManager, boolean isDebug) {
|
17
|
14
|
this.reactInstanceManager = reactInstanceManager;
|
18
|
15
|
this.devPermissionRequest = new DevPermissionRequest(isDebug);
|
19
|
|
- this.isDebug = isDebug;
|
20
|
16
|
}
|
21
|
17
|
|
22
|
|
- public void onActivityCreated(NavigationActivity activity) {
|
|
18
|
+ public void onActivityCreated(final NavigationActivity activity) {
|
23
|
19
|
reactInstanceManager.addReactInstanceEventListener(this);
|
24
|
20
|
waitingForAppLaunchEvent = true;
|
25
|
21
|
}
|
|
@@ -29,7 +25,7 @@ public class NavigationReactInitializer implements ReactInstanceManager.ReactIns
|
29
|
25
|
devPermissionRequest.askPermission(activity);
|
30
|
26
|
} else {
|
31
|
27
|
reactInstanceManager.onHostResume(activity, activity);
|
32
|
|
- checkBundleThenPrepareReact(activity);
|
|
28
|
+ prepareReactApp();
|
33
|
29
|
}
|
34
|
30
|
}
|
35
|
31
|
|
|
@@ -46,29 +42,7 @@ public class NavigationReactInitializer implements ReactInstanceManager.ReactIns
|
46
|
42
|
}
|
47
|
43
|
}
|
48
|
44
|
|
49
|
|
- private void checkBundleThenPrepareReact(final NavigationActivity activity) {
|
50
|
|
- if (isDebug) {
|
51
|
|
- reactInstanceManager.getDevSupportManager().isPackagerRunning(new PackagerStatusCallback() {
|
52
|
|
- @Override
|
53
|
|
- public void onPackagerStatusFetched(final boolean packagerIsRunning) {
|
54
|
|
- UiThread.post(new Runnable() {
|
55
|
|
- @Override
|
56
|
|
- public void run() {
|
57
|
|
- if (!packagerIsRunning) {
|
58
|
|
- activity.toast("Packager is not running!");
|
59
|
|
- } else {
|
60
|
|
- prepareReactAppWithWorkingBundle();
|
61
|
|
- }
|
62
|
|
- }
|
63
|
|
- });
|
64
|
|
- }
|
65
|
|
- });
|
66
|
|
- } else {
|
67
|
|
- prepareReactAppWithWorkingBundle();
|
68
|
|
- }
|
69
|
|
- }
|
70
|
|
-
|
71
|
|
- private void prepareReactAppWithWorkingBundle() {
|
|
45
|
+ private void prepareReactApp() {
|
72
|
46
|
if (shouldCreateContext()) {
|
73
|
47
|
reactInstanceManager.createReactContextInBackground();
|
74
|
48
|
} else if (waitingForAppLaunchEvent) {
|