Browse Source

NavigationReactInstance initialized each splash

Daniel Zlotin 8 years ago
parent
commit
41a0d4dc30

+ 19
- 7
android/app/src/main/java/com/reactnativenavigation/NavigationApplication.java View File

@@ -25,7 +25,6 @@ public abstract class NavigationApplication extends Application {
25 25
         super.onCreate();
26 26
         instance = this;
27 27
         handler = new Handler(getMainLooper());
28
-        navigationReactInstance = new NavigationReactInstance();
29 28
     }
30 29
 
31 30
     public void runOnMainThread(Runnable runnable) {
@@ -73,31 +72,44 @@ public abstract class NavigationApplication extends Application {
73 72
     }
74 73
 
75 74
     public ReactContext getReactContext() {
75
+        if (navigationReactInstance == null) {
76
+            return null;
77
+        }
76 78
         return navigationReactInstance.getReactInstanceManager().getCurrentReactContext();
77 79
     }
78 80
 
79 81
     public boolean isReactInstanceManagerInitialized() {
80
-        return navigationReactInstance.getReactInstanceManager() != null;
82
+        return navigationReactInstance != null && navigationReactInstance.getReactInstanceManager() != null;
81 83
     }
82 84
 
83
-    public abstract boolean isDebug();
84
-
85
-    @Nullable
86
-    public abstract List<ReactPackage> createAdditionalReactPackages();
87
-
88 85
     public void sendNavigatorEvent(String eventId, String navigatorEventId) {
86
+        if (navigationReactInstance == null) {
87
+            return;
88
+        }
89 89
         navigationReactInstance.getReactEventEmitter().sendNavigatorEvent(eventId, navigatorEventId);
90 90
     }
91 91
 
92 92
     public void sendEvent(String eventId, String navigatorEventId) {
93
+        if (navigationReactInstance == null) {
94
+            return;
95
+        }
93 96
         navigationReactInstance.getReactEventEmitter().sendEvent(eventId, navigatorEventId);
94 97
     }
95 98
 
96 99
     public void sendNavigatorEvent(String eventId, WritableMap arguments) {
100
+        if (navigationReactInstance == null) {
101
+            return;
102
+        }
97 103
         navigationReactInstance.getReactEventEmitter().sendEvent(eventId, arguments);
98 104
     }
99 105
 
100 106
     public void startReactContext() {
107
+        navigationReactInstance = new NavigationReactInstance();
101 108
         navigationReactInstance.startReactContextOnceInBackgroundAndExecuteJS();
102 109
     }
110
+
111
+    public abstract boolean isDebug();
112
+
113
+    @Nullable
114
+    public abstract List<ReactPackage> createAdditionalReactPackages();
103 115
 }

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/react/NavigationReactInstance.java View File

@@ -59,6 +59,7 @@ public class NavigationReactInstance {
59 59
 
60 60
     public void onHostDestroy() {
61 61
         reactInstanceManager.onHostDestroy();
62
+        reactInstanceManager.destroy();
62 63
     }
63 64
 
64 65
     private void replaceJsDevReloadListener() {