From 28efab0670f4c8c2a7bc5ac476cfdeabb29eec27 Mon Sep 17 00:00:00 2001 From: Denis Koroskin Date: Mon, 4 Jan 2016 13:07:54 -0800 Subject: [PATCH] Fix Android Views not clipping their content Summary: D2768643 disabled View clipping of FlatViewGroup's children by calling setClipChildren(false). Turns out, instead of disabling clipping on the View this method is called on, it disables clipping on the children, instead. While we want the clipping disabled on all children that are FlatViewGroups, it also means that everyone else gets the clipping disabled as well. This has issues with ScrollView that stopped clipping its scrolling content, resulting in visual glitches. To fix the issue, manually clip all the Views that are not FlatViewGroups. Reviewed By: ahmedre Differential Revision: D2792411 --- .../java/com/facebook/react/flat/FlatViewGroup.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatViewGroup.java b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatViewGroup.java index b10d34ed3..7a40710ec 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatViewGroup.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatViewGroup.java @@ -16,6 +16,7 @@ import javax.annotation.Nullable; import android.content.Context; import android.graphics.Canvas; +import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.view.MotionEvent; import android.view.View; @@ -56,6 +57,7 @@ import com.facebook.react.uimanager.ReactPointerEventsView; } private static final ArrayList LAYOUT_REQUESTS = new ArrayList<>(); + private static final Rect VIEW_BOUNDS = new Rect(); private @Nullable InvalidateCallback mInvalidateCallback; private DrawCommand[] mDrawCommands = DrawCommand.EMPTY_ARRAY; @@ -299,7 +301,16 @@ import com.facebook.react.uimanager.ReactPointerEventsView; /* package */ void drawNextChild(Canvas canvas) { View child = getChildAt(mDrawChildIndex); - super.drawChild(canvas, child, getDrawingTime()); + if (child instanceof FlatViewGroup) { + super.drawChild(canvas, child, getDrawingTime()); + } else { + // Make sure non-React Views clip properly. + canvas.save(); + child.getHitRect(VIEW_BOUNDS); + canvas.clipRect(VIEW_BOUNDS); + super.drawChild(canvas, child, getDrawingTime()); + canvas.restore(); + } ++mDrawChildIndex; }