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
This commit is contained in:
Denis Koroskin 2016-01-04 13:07:54 -08:00 committed by Ahmed El-Helw
parent 0f2a5cffa7
commit 28efab0670
1 changed files with 12 additions and 1 deletions

View File

@ -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<FlatViewGroup> 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;
}