Kaynağa Gözat

Add MainReactPackage only if wasn't added by the user

RNN's ReactNativeHost implementation prevented users from adding MainReactPackage
themselves, this forced users that wanted to use a custom MainReactPackage to extend
NavigationReactNativeHost which is a bit of an overkill for this simple use case.
Guy Carmeli 6 yıl önce
ebeveyn
işleme
c3fc99359f

+ 6
- 2
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationReactNativeHost.java Dosyayı Görüntüle

@@ -38,15 +38,19 @@ public class NavigationReactNativeHost extends ReactNativeHost {
38 38
     @Override
39 39
 	protected List<ReactPackage> getPackages() {
40 40
 		List<ReactPackage> packages = new ArrayList<>();
41
-		packages.add(new MainReactPackage());
41
+		boolean hasMainReactPackage = false;
42 42
 		packages.add(new NavigationPackage(this));
43 43
 		if (additionalReactPackages != null) {
44 44
 			for (ReactPackage p : additionalReactPackages) {
45
-				if (!(p instanceof MainReactPackage || p instanceof NavigationPackage)) {
45
+				if (!(p instanceof NavigationPackage)) {
46 46
 					packages.add(p);
47 47
 				}
48
+				if (p instanceof MainReactPackage) hasMainReactPackage = true;
48 49
 			}
49 50
 		}
51
+        if (!hasMainReactPackage) {
52
+            packages.add(new MainReactPackage());
53
+        }
50 54
 		return packages;
51 55
 	}
52 56
 }