Browse Source

v0.62 Support (#5795)

react native 0.62 Support
Jason Safaiyeh 4 years ago
parent
commit
4bfa7c5092
No account linked to committer's email address

+ 4
- 0
lib/android/app/build.gradle View File

@@ -79,6 +79,10 @@ android {
79 79
             dimension "RNN.reactNativeVersion"
80 80
             buildConfigField("int", "REACT_NATVE_VERSION_MINOR", "60")
81 81
         }
82
+        reactNative62 {
83
+            dimension "RNN.reactNativeVersion"
84
+            buildConfigField("int", "REACT_NATVE_VERSION_MINOR", "62")
85
+        }
82 86
     }
83 87
 }
84 88
 

+ 22
- 0
lib/android/app/src/reactNative62/java/reactnativenavigation/react/DevBundleDownloadListenerAdapter.java View File

@@ -0,0 +1,22 @@
1
+package com.reactnativenavigation.react;
2
+
3
+import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
4
+
5
+import javax.annotation.Nullable;
6
+
7
+public class DevBundleDownloadListenerAdapter implements DevBundleDownloadListener, NavigationDevBundleDownloadListener {
8
+    @Override
9
+    public void onSuccess() {
10
+        onSuccess();
11
+    }
12
+
13
+    @Override
14
+    public void onProgress(@Nullable String status, @Nullable Integer done, @Nullable Integer total) {
15
+
16
+    }
17
+
18
+    @Override
19
+    public void onFailure(Exception cause) {
20
+
21
+    }
22
+}

+ 22
- 0
lib/android/app/src/reactNative62/java/reactnativenavigation/react/JsDevReloadHandlerFacade.java View File

@@ -0,0 +1,22 @@
1
+package com.reactnativenavigation.react;
2
+
3
+import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
4
+
5
+import javax.annotation.Nullable;
6
+
7
+public class JsDevReloadHandlerFacade implements DevBundleDownloadListener, NavigationDevBundleDownloadListener {
8
+    @Override
9
+    public void onSuccess() {
10
+        onSuccess();
11
+    }
12
+
13
+    @Override
14
+    public void onProgress(@Nullable String status, @Nullable Integer done, @Nullable Integer total) {
15
+
16
+    }
17
+
18
+    @Override
19
+    public void onFailure(Exception cause) {
20
+
21
+    }
22
+}

+ 107
- 0
lib/android/app/src/reactNative62/java/reactnativenavigation/react/NavigationReactNativeHost.java View File

@@ -0,0 +1,107 @@
1
+package com.reactnativenavigation.react;
2
+
3
+import android.app.Application;
4
+import androidx.annotation.NonNull;
5
+import androidx.annotation.Nullable;
6
+
7
+import com.facebook.infer.annotation.Assertions;
8
+import com.facebook.react.ReactInstanceManager;
9
+import com.facebook.react.ReactInstanceManagerBuilder;
10
+import com.facebook.react.ReactNativeHost;
11
+import com.facebook.react.ReactPackage;
12
+import com.facebook.react.common.LifecycleState;
13
+import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
14
+import com.facebook.react.shell.MainReactPackage;
15
+import com.reactnativenavigation.NavigationApplication;
16
+
17
+import java.util.ArrayList;
18
+import java.util.List;
19
+
20
+/**
21
+ * Default implementation of {@link ReactNativeHost} that includes {@link NavigationPackage}
22
+ * and user-defined additional packages.
23
+ */
24
+public class NavigationReactNativeHost extends ReactNativeHost implements BundleDownloadListenerProvider {
25
+
26
+    private final boolean isDebug;
27
+    private final List<ReactPackage> additionalReactPackages;
28
+    private @Nullable NavigationDevBundleDownloadListener bundleListener;
29
+    private final DevBundleDownloadListener bundleListenerMediator = new DevBundleDownloadListenerAdapter() {
30
+        @Override
31
+        public void onSuccess() {
32
+            if (bundleListener != null) {
33
+                bundleListener.onSuccess();
34
+            }
35
+        }
36
+    };
37
+
38
+    public NavigationReactNativeHost(NavigationApplication application) {
39
+        this(application, application.isDebug(), application.createAdditionalReactPackages());
40
+    }
41
+
42
+    @SuppressWarnings("WeakerAccess")
43
+    public NavigationReactNativeHost(Application application, boolean isDebug, final List<ReactPackage> additionalReactPackages) {
44
+        super(application);
45
+        this.isDebug = isDebug;
46
+        this.additionalReactPackages = additionalReactPackages;
47
+    }
48
+
49
+    @Override
50
+    public void setBundleLoaderListener(NavigationDevBundleDownloadListener listener) {
51
+        bundleListener = listener;
52
+    }
53
+
54
+    @Override
55
+    public boolean getUseDeveloperSupport() {
56
+        return isDebug;
57
+    }
58
+
59
+    @Override
60
+    protected List<ReactPackage> getPackages() {
61
+        List<ReactPackage> packages = new ArrayList<>();
62
+        boolean hasMainReactPackage = false;
63
+        packages.add(new NavigationPackage(this));
64
+        if (additionalReactPackages != null) {
65
+            for (ReactPackage p : additionalReactPackages) {
66
+                if (!(p instanceof NavigationPackage)) {
67
+                    packages.add(p);
68
+                }
69
+                if (p instanceof MainReactPackage) hasMainReactPackage = true;
70
+            }
71
+        }
72
+        if (!hasMainReactPackage) {
73
+            packages.add(new MainReactPackage());
74
+        }
75
+        return packages;
76
+    }
77
+
78
+    protected ReactInstanceManager createReactInstanceManager() {
79
+        ReactInstanceManagerBuilder builder = ReactInstanceManager.builder()
80
+                .setApplication(getApplication())
81
+                .setJSMainModulePath(getJSMainModuleName())
82
+                .setUseDeveloperSupport(getUseDeveloperSupport())
83
+                .setRedBoxHandler(getRedBoxHandler())
84
+                .setJavaScriptExecutorFactory(getJavaScriptExecutorFactory())
85
+                .setUIImplementationProvider(getUIImplementationProvider())
86
+                .setInitialLifecycleState(LifecycleState.BEFORE_CREATE)
87
+                .setDevBundleDownloadListener(getDevBundleDownloadListener());
88
+
89
+        for (ReactPackage reactPackage : getPackages()) {
90
+            builder.addPackage(reactPackage);
91
+        }
92
+
93
+        String jsBundleFile = getJSBundleFile();
94
+        if (jsBundleFile != null) {
95
+            builder.setJSBundleFile(jsBundleFile);
96
+        } else {
97
+            builder.setBundleAssetName(Assertions.assertNotNull(getBundleAssetName()));
98
+        }
99
+        return builder.build();
100
+    }
101
+
102
+    @SuppressWarnings("WeakerAccess")
103
+    @NonNull
104
+    protected DevBundleDownloadListener getDevBundleDownloadListener() {
105
+        return bundleListenerMediator;
106
+    }
107
+}

+ 22
- 0
lib/android/app/src/reactNative62/java/reactnativenavigation/react/ReloadHandlerFacade.java View File

@@ -0,0 +1,22 @@
1
+package com.reactnativenavigation.react;
2
+
3
+import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
4
+
5
+import javax.annotation.Nullable;
6
+
7
+public abstract class ReloadHandlerFacade implements DevBundleDownloadListener {
8
+    @Override
9
+    public void onSuccess() {
10
+
11
+    }
12
+
13
+    @Override
14
+    public void onProgress(@Nullable String status, @Nullable Integer done, @Nullable Integer total) {
15
+
16
+    }
17
+
18
+    @Override
19
+    public void onFailure(Exception cause) {
20
+
21
+    }
22
+}