Pārlūkot izejas kodu

Implement a synchronous UiImplementation

Related to #2892

To use it, Override `createReactNativeHost` in MainApplication as follows:

```java
    @Override
    protected ReactNativeHost createReactNativeHost() {
        return new NavigationReactNativeHost(this) {
            @Override
            protected UIImplementationProvider getUIImplementationProvider() {
                return new SyncUiImplementation.Provider();
            }
        };
    }
```
Guy Carmeli 6 gadus atpakaļ
vecāks
revīzija
4c8d48b1b5

+ 83
- 0
lib/android/app/src/main/java/com/reactnativenavigation/react/SyncUiImplementation.java Parādīt failu

@@ -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.MeasureSpecProvider;
9
+import com.facebook.react.uimanager.SizeMonitoringFrameLayout;
10
+import com.facebook.react.uimanager.ThemedReactContext;
11
+import com.facebook.react.uimanager.UIImplementation;
12
+import com.facebook.react.uimanager.UIImplementationProvider;
13
+import com.facebook.react.uimanager.UIManagerModule;
14
+import com.facebook.react.uimanager.ViewManager;
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
+}

+ 7
- 0
playground/android/app/src/main/java/com/reactnativenavigation/playground/MainApplication.java Parādīt failu

@@ -4,8 +4,10 @@ import android.support.annotation.Nullable;
4 4
 
5 5
 import com.facebook.react.ReactNativeHost;
6 6
 import com.facebook.react.ReactPackage;
7
+import com.facebook.react.uimanager.UIImplementationProvider;
7 8
 import com.reactnativenavigation.NavigationApplication;
8 9
 import com.reactnativenavigation.react.NavigationReactNativeHost;
10
+import com.reactnativenavigation.react.SyncUiImplementation;
9 11
 
10 12
 import java.util.List;
11 13
 
@@ -24,6 +26,11 @@ public class MainApplication extends NavigationApplication {
24 26
             protected String getJSMainModuleName() {
25 27
                 return "index";
26 28
             }
29
+
30
+            @Override
31
+            protected UIImplementationProvider getUIImplementationProvider() {
32
+                return new SyncUiImplementation.Provider();
33
+            }
27 34
         };
28 35
     }
29 36