Parcourir la source

Fixing NPE found on issue #2695 (#2976)

There's a roundabout manner of obtaining the react context on initialisation that is null on some instances (https://github.com/wix/react-native-navigation/issues/2695), including errors on startup that prevents debugging on console. (For instance, throwing an error on index before starting the app)

It is solved by sending the same context given on method onReactContextInitialized, instead of discarding it and calling getReactContext.
Denis Ikeda il y a 6 ans
Parent
révision
085b3c9c90

+ 3
- 3
android/app/src/main/java/com/reactnativenavigation/react/NavigationReactGateway.java Voir le fichier

@@ -110,8 +110,8 @@ public class NavigationReactGateway implements ReactGateway {
110 110
 	}
111 111
 
112 112
 	//TODO temp hack
113
-	private void onReactContextInitialized() {
114
-		reactEventEmitter = new NavigationReactEventEmitter(getReactContext());
113
+	private void onReactContextInitialized(ReactContext context) {
114
+		reactEventEmitter = new NavigationReactEventEmitter(context);
115 115
 	}
116 116
 
117 117
 	private static class ReactNativeHostImpl extends ReactNativeHost implements ReactInstanceManager.ReactInstanceEventListener {
@@ -171,7 +171,7 @@ public class NavigationReactGateway implements ReactGateway {
171 171
 
172 172
 		@Override
173 173
 		public void onReactContextInitialized(ReactContext context) {
174
-			((NavigationReactGateway) NavigationApplication.instance.getReactGateway()).onReactContextInitialized();
174
+			((NavigationReactGateway) NavigationApplication.instance.getReactGateway()).onReactContextInitialized(context);
175 175
 			NavigationApplication.instance.onReactInitialized(context);
176 176
 		}
177 177