Skip to content

Commit

Permalink
Fix YellowBox removal (#5127)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
guyca authored May 20, 2019
1 parent a346f3f commit ecadcb0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<View> YellowBackgroundMather(ViewGroup vg) {
return child1 -> child1.getBackground() instanceof ReactViewBackgroundDrawable && ((ReactViewBackgroundDrawable) child1.getBackground()).getColor() == YELLOW_BOX_COLOR;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void onReactViewDestroy_yellowBoxIsAddedBackToParent() {
@Test
public void onChildViewAdded() {
uut.onChildViewAdded(parent, yellowBox);
dispatchPreDraw(yellowBox);
verify(yellowBoxHelper).isYellowBox(parent, yellowBox);
}

Expand Down

0 comments on commit ecadcb0

Please sign in to comment.