Browse Source

Improve RN 57 support for Wix fork

This commit adds a dedicated RN 57 build flavour for the Wix fork, where 506f920838 is reverted.
The revert reintroduced UiImplementationProvider which is required to pass SyncUiImplementation to UiManager.
Guy Carmeli 6 years ago
parent
commit
e0bc06359b

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

@@ -60,6 +60,9 @@ android {
60 60
         reactNative57 {
61 61
             dimension "RNN.reactNativeVersion"
62 62
         }
63
+        reactNative57WixFork {
64
+            dimension "RNN.reactNativeVersion"
65
+        }
63 66
     }
64 67
 }
65 68
 

+ 28
- 0
lib/android/app/src/reactNative57WixFork/java/com/reactnativenavigation/react/DevBundleDownloadListenerAdapter.java View File

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

+ 28
- 0
lib/android/app/src/reactNative57WixFork/java/com/reactnativenavigation/react/JsDevReloadHandlerFacade.java View File

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

+ 106
- 0
lib/android/app/src/reactNative57WixFork/java/com/reactnativenavigation/react/NavigationReactNativeHost.java View File

@@ -0,0 +1,106 @@
1
+package com.reactnativenavigation.react;
2
+
3
+import android.app.Application;
4
+import android.support.annotation.NonNull;
5
+import android.support.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
+                .setInitialLifecycleState(LifecycleState.BEFORE_CREATE)
86
+                .setDevBundleDownloadListener(getDevBundleDownloadListener());
87
+
88
+        for (ReactPackage reactPackage : getPackages()) {
89
+            builder.addPackage(reactPackage);
90
+        }
91
+
92
+        String jsBundleFile = getJSBundleFile();
93
+        if (jsBundleFile != null) {
94
+            builder.setJSBundleFile(jsBundleFile);
95
+        } else {
96
+            builder.setBundleAssetName(Assertions.assertNotNull(getBundleAssetName()));
97
+        }
98
+        return builder.build();
99
+    }
100
+
101
+    @SuppressWarnings("WeakerAccess")
102
+    @NonNull
103
+    protected DevBundleDownloadListener getDevBundleDownloadListener() {
104
+        return bundleListenerMediator;
105
+    }
106
+}

+ 25
- 0
lib/android/app/src/reactNative57WixFork/java/com/reactnativenavigation/react/ReloadHandlerFacade.java View File

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

+ 83
- 0
lib/android/app/src/reactNative57WixFork/java/com/reactnativenavigation/react/SyncUiImplementation.java View File

@@ -0,0 +1,83 @@
1
+package com.reactnativenavigation.react;
2
+
3
+import android.support.annotation.Nullable;
4
+
5
+import com.facebook.react.bridge.ReactApplicationContext;
6
+import com.facebook.react.bridge.ReadableArray;
7
+import com.facebook.react.bridge.ReadableMap;
8
+import com.facebook.react.uimanager.ThemedReactContext;
9
+import com.facebook.react.uimanager.UIImplementation;
10
+import com.facebook.react.uimanager.UIImplementationProvider;
11
+import com.facebook.react.uimanager.UIManagerModule;
12
+import com.facebook.react.uimanager.ViewManager;
13
+import com.facebook.react.uimanager.common.MeasureSpecProvider;
14
+import com.facebook.react.uimanager.common.SizeMonitoringFrameLayout;
15
+import com.facebook.react.uimanager.events.EventDispatcher;
16
+
17
+import java.util.List;
18
+
19
+@SuppressWarnings("WeakerAccess")
20
+public class SyncUiImplementation extends UIImplementation {
21
+    private static final Object lock = new Object();
22
+
23
+    public static class Provider extends UIImplementationProvider {
24
+        @Override
25
+        public UIImplementation createUIImplementation(ReactApplicationContext reactContext, List<ViewManager> viewManagerList, EventDispatcher eventDispatcher, int minTimeLeftInFrameForNonBatchedOperationMs) {
26
+            return new SyncUiImplementation(reactContext, viewManagerList, eventDispatcher, minTimeLeftInFrameForNonBatchedOperationMs);
27
+        }
28
+
29
+        @Override
30
+        public UIImplementation createUIImplementation(ReactApplicationContext reactContext, UIManagerModule.ViewManagerResolver viewManagerResolver, EventDispatcher eventDispatcher, int minTimeLeftInFrameForNonBatchedOperationMs) {
31
+            return new SyncUiImplementation(reactContext, viewManagerResolver, eventDispatcher, minTimeLeftInFrameForNonBatchedOperationMs);
32
+        }
33
+    }
34
+
35
+    public SyncUiImplementation(ReactApplicationContext reactContext, List<ViewManager> viewManagerList, EventDispatcher eventDispatcher, int minTimeLeftInFrameForNonBatchedOperationMs) {
36
+        super(reactContext, viewManagerList, eventDispatcher, minTimeLeftInFrameForNonBatchedOperationMs);
37
+    }
38
+
39
+    public SyncUiImplementation(ReactApplicationContext reactContext, UIManagerModule.ViewManagerResolver viewManagerResolver, EventDispatcher eventDispatcher, int minTimeLeftInFrameForNonBatchedOperationMs) {
40
+        super(reactContext, viewManagerResolver, eventDispatcher, minTimeLeftInFrameForNonBatchedOperationMs);
41
+    }
42
+
43
+    @Override
44
+    public void manageChildren(
45
+            int viewTag,
46
+            @Nullable ReadableArray moveFrom,
47
+            @Nullable ReadableArray moveTo,
48
+            @Nullable ReadableArray addChildTags,
49
+            @Nullable ReadableArray addAtIndices,
50
+            @Nullable ReadableArray removeFrom) {
51
+        synchronized (lock) {
52
+            super.manageChildren(viewTag, moveFrom, moveTo, addChildTags, addAtIndices, removeFrom);
53
+        }
54
+    }
55
+
56
+    @Override
57
+    public void setChildren(int viewTag, ReadableArray childrenTags) {
58
+        synchronized (lock) {
59
+            super.setChildren(viewTag, childrenTags);
60
+        }
61
+    }
62
+
63
+    @Override
64
+    public void createView(int tag, String className, int rootViewTag, ReadableMap props) {
65
+        synchronized (lock) {
66
+            super.createView(tag, className, rootViewTag, props);
67
+        }
68
+    }
69
+
70
+    @Override
71
+    public void removeRootShadowNode(int rootViewTag) {
72
+        synchronized (lock) {
73
+            super.removeRootShadowNode(rootViewTag);
74
+        }
75
+    }
76
+
77
+    @Override
78
+    public <T extends SizeMonitoringFrameLayout & MeasureSpecProvider> void registerRootView(T rootView, int tag, ThemedReactContext context) {
79
+        synchronized (lock) {
80
+            super.registerRootView(rootView, tag, context);
81
+        }
82
+    }
83
+}