Browse Source

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 years ago
parent
commit
ecadcb0f35
No account linked to committer's email address

+ 7
- 3
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/YellowBoxDelegate.java View File

4
 import android.view.View;
4
 import android.view.View;
5
 import android.view.ViewGroup;
5
 import android.view.ViewGroup;
6
 
6
 
7
+import com.reactnativenavigation.utils.UiUtils;
8
+
7
 import java.util.ArrayList;
9
 import java.util.ArrayList;
8
 import java.util.List;
10
 import java.util.List;
9
 
11
 
22
     }
24
     }
23
 
25
 
24
     public void onChildViewAdded(View parent, View child) {
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
     void onYellowBoxAdded(View parent) {
34
     void onYellowBoxAdded(View parent) {

+ 13
- 1
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/YellowBoxHelper.java View File

1
 package com.reactnativenavigation.viewcontrollers;
1
 package com.reactnativenavigation.viewcontrollers;
2
 
2
 
3
+import android.support.annotation.NonNull;
3
 import android.view.View;
4
 import android.view.View;
4
 import android.view.ViewGroup;
5
 import android.view.ViewGroup;
5
 
6
 
7
+import com.facebook.react.views.view.ReactViewBackgroundDrawable;
8
+import com.reactnativenavigation.utils.ViewUtils;
9
+
6
 class YellowBoxHelper {
10
 class YellowBoxHelper {
11
+    private final static int YELLOW_BOX_COLOR = -218449360;
12
+
7
     boolean isYellowBox(View parent, View child) {
13
     boolean isYellowBox(View parent, View child) {
8
         return parent instanceof ViewGroup &&
14
         return parent instanceof ViewGroup &&
9
                child instanceof ViewGroup &&
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 View File

53
     @Test
53
     @Test
54
     public void onChildViewAdded() {
54
     public void onChildViewAdded() {
55
         uut.onChildViewAdded(parent, yellowBox);
55
         uut.onChildViewAdded(parent, yellowBox);
56
+        dispatchPreDraw(yellowBox);
56
         verify(yellowBoxHelper).isYellowBox(parent, yellowBox);
57
         verify(yellowBoxHelper).isYellowBox(parent, yellowBox);
57
     }
58
     }
58
 
59