Quellcode durchsuchen

implemented changes

Daniel Zlotin vor 8 Jahren
Ursprung
Commit
79ca9e56ce

+ 8
- 8
android/app/src/main/java/com/reactnativenavigation/NavigationApplication.java Datei anzeigen

@@ -4,19 +4,22 @@ import android.app.Application;
4 4
 import android.os.Handler;
5 5
 import android.support.annotation.Nullable;
6 6
 
7
+import com.facebook.react.ReactApplication;
8
+import com.facebook.react.ReactNativeHost;
7 9
 import com.facebook.react.ReactPackage;
8 10
 import com.facebook.react.bridge.ReactContext;
9 11
 import com.facebook.react.bridge.WritableMap;
10 12
 import com.reactnativenavigation.react.NavigationReactGateway;
11 13
 import com.reactnativenavigation.react.ReactGateway;
14
+import com.reactnativenavigation.react.ReactGatewayHost;
12 15
 
13 16
 import java.util.List;
14 17
 
15
-public abstract class NavigationApplication extends Application {
18
+public abstract class NavigationApplication extends Application implements ReactApplication {
16 19
 
17 20
     public static NavigationApplication instance;
18 21
 
19
-    private ReactGateway reactGateway;
22
+    private ReactGatewayHost reactGateway;
20 23
     private Handler handler;
21 24
 
22 25
     @Override
@@ -51,12 +54,9 @@ public abstract class NavigationApplication extends Application {
51 54
         // nothing
52 55
     }
53 56
 
54
-    public String getJsEntryFileName() {
55
-        return "index.android";
56
-    }
57
-
58
-    public String getBundleAssetName() {
59
-        return "index.android.bundle";
57
+    @Override
58
+    public ReactNativeHost getReactNativeHost() {
59
+        return reactGateway;
60 60
     }
61 61
 
62 62
     public abstract boolean isDebug();

+ 15
- 18
android/app/src/main/java/com/reactnativenavigation/react/NavigationReactGateway.java Datei anzeigen

@@ -3,7 +3,6 @@ package com.reactnativenavigation.react;
3 3
 import android.app.Activity;
4 4
 import android.content.Intent;
5 5
 
6
-import com.facebook.react.LifecycleState;
7 6
 import com.facebook.react.ReactInstanceManager;
8 7
 import com.facebook.react.ReactPackage;
9 8
 import com.facebook.react.bridge.ReactContext;
@@ -16,13 +15,14 @@ import com.reactnativenavigation.bridge.NavigationReactPackage;
16 15
 import java.util.ArrayList;
17 16
 import java.util.List;
18 17
 
19
-public class NavigationReactGateway implements ReactGateway, ReactInstanceManager.ReactInstanceEventListener {
18
+public class NavigationReactGateway extends ReactGatewayHost implements ReactInstanceManager.ReactInstanceEventListener {
20 19
 
21 20
     private OnJsDevReloadListener onJsDevReloadListener;
22 21
     private ReactInstanceManager reactInstanceManager;
23 22
     private NavigationReactEventEmitter reactEventEmitter;
24 23
 
25 24
     public NavigationReactGateway() {
25
+        super(NavigationApplication.instance);
26 26
         reactInstanceManager = createReactInstanceManager();
27 27
     }
28 28
 
@@ -88,29 +88,26 @@ public class NavigationReactGateway implements ReactGateway, ReactInstanceManage
88 88
         }).replace();
89 89
     }
90 90
 
91
-    private ReactInstanceManager createReactInstanceManager() {
92
-        ReactInstanceManager.Builder builder = ReactInstanceManager.builder()
93
-                .setApplication(NavigationApplication.instance)
94
-                .setJSMainModuleName(NavigationApplication.instance.getJsEntryFileName())
95
-                .setBundleAssetName(NavigationApplication.instance.getBundleAssetName())
96
-                .setUseDeveloperSupport(NavigationApplication.instance.isDebug())
97
-                .setInitialLifecycleState(LifecycleState.BEFORE_RESUME);
98
-
99
-        for (ReactPackage reactPackage : createReactPackages()) {
100
-            builder.addPackage(reactPackage);
101
-        }
102
-
103
-        ReactInstanceManager manager = builder.build();
104
-
91
+    @Override
92
+    protected ReactInstanceManager createReactInstanceManager() {
93
+        ReactInstanceManager manager = super.createReactInstanceManager();
105 94
         if (NavigationApplication.instance.isDebug()) {
106 95
             replaceJsDevReloadListener(manager);
107 96
         }
108
-
109 97
         manager.addReactInstanceEventListener(this);
110
-
111 98
         return manager;
112 99
     }
113 100
 
101
+    @Override
102
+    protected boolean getUseDeveloperSupport() {
103
+        return NavigationApplication.instance.isDebug();
104
+    }
105
+
106
+    @Override
107
+    protected List<ReactPackage> getPackages() {
108
+        return createReactPackages();
109
+    }
110
+
114 111
     private List<ReactPackage> createReactPackages() {
115 112
         List<ReactPackage> list = new ArrayList<>();
116 113
         list.add(new MainReactPackage());

+ 11
- 0
android/app/src/main/java/com/reactnativenavigation/react/ReactGatewayHost.java Datei anzeigen

@@ -0,0 +1,11 @@
1
+package com.reactnativenavigation.react;
2
+
3
+import android.app.Application;
4
+
5
+import com.facebook.react.ReactNativeHost;
6
+
7
+public abstract class ReactGatewayHost extends ReactNativeHost implements ReactGateway {
8
+    protected ReactGatewayHost(Application application) {
9
+        super(application);
10
+    }
11
+}

+ 1
- 1
example-redux/android/app/src/main/AndroidManifest.xml Datei anzeigen

@@ -4,7 +4,7 @@
4 4
     <uses-permission android:name="android.permission.INTERNET" />
5 5
 
6 6
     <application
7
-        android:name=".App"
7
+        android:name=".MainApplication"
8 8
         android:allowBackup="true"
9 9
         android:icon="@mipmap/ic_launcher"
10 10
         android:label="@string/app_name"

example-redux/android/app/src/main/java/com/exampleredux/App.java → example-redux/android/app/src/main/java/com/exampleredux/MainApplication.java Datei anzeigen

@@ -1,22 +1,23 @@
1 1
 package com.exampleredux;
2 2
 
3
-import android.support.annotation.NonNull;
3
+import android.support.annotation.Nullable;
4 4
 
5 5
 import com.facebook.react.ReactPackage;
6 6
 import com.reactnativenavigation.NavigationApplication;
7 7
 
8
-import java.util.Collections;
9 8
 import java.util.List;
10 9
 
11
-public class App extends NavigationApplication {
10
+public class MainApplication extends NavigationApplication {
11
+
12
+
12 13
     @Override
13 14
     public boolean isDebug() {
14 15
         return BuildConfig.DEBUG;
15 16
     }
16 17
 
17
-    @NonNull
18
+    @Nullable
18 19
     @Override
19 20
     public List<ReactPackage> createAdditionalReactPackages() {
20
-        return Collections.emptyList();
21
+        return null;
21 22
     }
22 23
 }