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
         super.onCreate();
25
         super.onCreate();
26
         instance = this;
26
         instance = this;
27
         handler = new Handler(getMainLooper());
27
         handler = new Handler(getMainLooper());
28
-        navigationReactInstance = new NavigationReactInstance();
29
     }
28
     }
30
 
29
 
31
     public void runOnMainThread(Runnable runnable) {
30
     public void runOnMainThread(Runnable runnable) {
73
     }
72
     }
74
 
73
 
75
     public ReactContext getReactContext() {
74
     public ReactContext getReactContext() {
75
+        if (navigationReactInstance == null) {
76
+            return null;
77
+        }
76
         return navigationReactInstance.getReactInstanceManager().getCurrentReactContext();
78
         return navigationReactInstance.getReactInstanceManager().getCurrentReactContext();
77
     }
79
     }
78
 
80
 
79
     public boolean isReactInstanceManagerInitialized() {
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
     public void sendNavigatorEvent(String eventId, String navigatorEventId) {
85
     public void sendNavigatorEvent(String eventId, String navigatorEventId) {
86
+        if (navigationReactInstance == null) {
87
+            return;
88
+        }
89
         navigationReactInstance.getReactEventEmitter().sendNavigatorEvent(eventId, navigatorEventId);
89
         navigationReactInstance.getReactEventEmitter().sendNavigatorEvent(eventId, navigatorEventId);
90
     }
90
     }
91
 
91
 
92
     public void sendEvent(String eventId, String navigatorEventId) {
92
     public void sendEvent(String eventId, String navigatorEventId) {
93
+        if (navigationReactInstance == null) {
94
+            return;
95
+        }
93
         navigationReactInstance.getReactEventEmitter().sendEvent(eventId, navigatorEventId);
96
         navigationReactInstance.getReactEventEmitter().sendEvent(eventId, navigatorEventId);
94
     }
97
     }
95
 
98
 
96
     public void sendNavigatorEvent(String eventId, WritableMap arguments) {
99
     public void sendNavigatorEvent(String eventId, WritableMap arguments) {
100
+        if (navigationReactInstance == null) {
101
+            return;
102
+        }
97
         navigationReactInstance.getReactEventEmitter().sendEvent(eventId, arguments);
103
         navigationReactInstance.getReactEventEmitter().sendEvent(eventId, arguments);
98
     }
104
     }
99
 
105
 
100
     public void startReactContext() {
106
     public void startReactContext() {
107
+        navigationReactInstance = new NavigationReactInstance();
101
         navigationReactInstance.startReactContextOnceInBackgroundAndExecuteJS();
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
 
59
 
60
     public void onHostDestroy() {
60
     public void onHostDestroy() {
61
         reactInstanceManager.onHostDestroy();
61
         reactInstanceManager.onHostDestroy();
62
+        reactInstanceManager.destroy();
62
     }
63
     }
63
 
64
 
64
     private void replaceJsDevReloadListener() {
65
     private void replaceJsDevReloadListener() {