Selaa lähdekoodia

Fix YellowBox removal (#5127)

After migrating to RN 0.59, view creation timings have changed a bit.
Seems like ruining this logic on pre draw sorts things out.

Fixes #5124
Guy Carmeli 5 vuotta sitten
vanhempi
commit
ecadcb0f35
No account linked to committer's email address

+ 7
- 3
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/YellowBoxDelegate.java Näytä tiedosto

@@ -4,6 +4,8 @@ import android.support.annotation.RestrictTo;
4 4
 import android.view.View;
5 5
 import android.view.ViewGroup;
6 6
 
7
+import com.reactnativenavigation.utils.UiUtils;
8
+
7 9
 import java.util.ArrayList;
8 10
 import java.util.List;
9 11
 
@@ -22,9 +24,11 @@ public class YellowBoxDelegate {
22 24
     }
23 25
 
24 26
     public void onChildViewAdded(View parent, View child) {
25
-        if (yellowBoxHelper.isYellowBox(parent, child)) {
26
-            onYellowBoxAdded(parent);
27
-        }
27
+        UiUtils.runOnPreDrawOnce(child, () -> {
28
+            if (yellowBoxHelper.isYellowBox(parent, child)) {
29
+                onYellowBoxAdded(parent);
30
+            }
31
+        });
28 32
     }
29 33
 
30 34
     void onYellowBoxAdded(View parent) {

+ 13
- 1
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/YellowBoxHelper.java Näytä tiedosto

@@ -1,12 +1,24 @@
1 1
 package com.reactnativenavigation.viewcontrollers;
2 2
 
3
+import android.support.annotation.NonNull;
3 4
 import android.view.View;
4 5
 import android.view.ViewGroup;
5 6
 
7
+import com.facebook.react.views.view.ReactViewBackgroundDrawable;
8
+import com.reactnativenavigation.utils.ViewUtils;
9
+
6 10
 class YellowBoxHelper {
11
+    private final static int YELLOW_BOX_COLOR = -218449360;
12
+
7 13
     boolean isYellowBox(View parent, View child) {
8 14
         return parent instanceof ViewGroup &&
9 15
                child instanceof ViewGroup &&
10
-               ((ViewGroup) parent).getChildCount() > 1;
16
+               ((ViewGroup) parent).getChildCount() > 1 &&
17
+               !ViewUtils.findChildrenByClassRecursive((ViewGroup) child, View.class, YellowBackgroundMather((ViewGroup) child)).isEmpty();
18
+    }
19
+
20
+    @NonNull
21
+    private static ViewUtils.Matcher<View> YellowBackgroundMather(ViewGroup vg) {
22
+        return child1 -> child1.getBackground() instanceof ReactViewBackgroundDrawable && ((ReactViewBackgroundDrawable) child1.getBackground()).getColor() == YELLOW_BOX_COLOR;
11 23
     }
12 24
 }

+ 1
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/YellowBoxDelegateTest.java Näytä tiedosto

@@ -53,6 +53,7 @@ public class YellowBoxDelegateTest extends BaseTest {
53 53
     @Test
54 54
     public void onChildViewAdded() {
55 55
         uut.onChildViewAdded(parent, yellowBox);
56
+        dispatchPreDraw(yellowBox);
56 57
         verify(yellowBoxHelper).isYellowBox(parent, yellowBox);
57 58
     }
58 59