diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/YellowBoxDelegate.java b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/YellowBoxDelegate.java index 3d6e24c5e6a..0c7999c7917 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/YellowBoxDelegate.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/YellowBoxDelegate.java @@ -4,6 +4,8 @@ import android.view.View; import android.view.ViewGroup; +import com.reactnativenavigation.utils.UiUtils; + import java.util.ArrayList; import java.util.List; @@ -22,9 +24,11 @@ public YellowBoxDelegate() { } public void onChildViewAdded(View parent, View child) { - if (yellowBoxHelper.isYellowBox(parent, child)) { - onYellowBoxAdded(parent); - } + UiUtils.runOnPreDrawOnce(child, () -> { + if (yellowBoxHelper.isYellowBox(parent, child)) { + onYellowBoxAdded(parent); + } + }); } void onYellowBoxAdded(View parent) { diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/YellowBoxHelper.java b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/YellowBoxHelper.java index 472371e558c..816d059250b 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/YellowBoxHelper.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/YellowBoxHelper.java @@ -1,12 +1,24 @@ package com.reactnativenavigation.viewcontrollers; +import android.support.annotation.NonNull; import android.view.View; import android.view.ViewGroup; +import com.facebook.react.views.view.ReactViewBackgroundDrawable; +import com.reactnativenavigation.utils.ViewUtils; + class YellowBoxHelper { + private final static int YELLOW_BOX_COLOR = -218449360; + boolean isYellowBox(View parent, View child) { return parent instanceof ViewGroup && child instanceof ViewGroup && - ((ViewGroup) parent).getChildCount() > 1; + ((ViewGroup) parent).getChildCount() > 1 && + !ViewUtils.findChildrenByClassRecursive((ViewGroup) child, View.class, YellowBackgroundMather((ViewGroup) child)).isEmpty(); + } + + @NonNull + private static ViewUtils.Matcher YellowBackgroundMather(ViewGroup vg) { + return child1 -> child1.getBackground() instanceof ReactViewBackgroundDrawable && ((ReactViewBackgroundDrawable) child1.getBackground()).getColor() == YELLOW_BOX_COLOR; } } diff --git a/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/YellowBoxDelegateTest.java b/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/YellowBoxDelegateTest.java index ca6fb45b170..956daf06143 100644 --- a/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/YellowBoxDelegateTest.java +++ b/lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/YellowBoxDelegateTest.java @@ -53,6 +53,7 @@ public void onReactViewDestroy_yellowBoxIsAddedBackToParent() { @Test public void onChildViewAdded() { uut.onChildViewAdded(parent, yellowBox); + dispatchPreDraw(yellowBox); verify(yellowBoxHelper).isYellowBox(parent, yellowBox); }