mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-09 09:30:10 +08:00
Support rounded clipping
Summary: Support rounded clipping in Nodes. Before, if a view had a radius and had overflow of hidden, its children could still draw outside of it (specifically, in the area between the rounded rect and square rect) - this is due to the fact that clipping is, by default, rectangular. This patch supports this type of rounded clipping. Differential Revision: D3634861
This commit is contained in:
@@ -60,7 +60,6 @@ import com.facebook.react.views.view.ReactClippingViewGroupHelper;
|
||||
private boolean mBackingViewIsCreated;
|
||||
private @Nullable DrawView mDrawView;
|
||||
private @Nullable DrawBackgroundColor mDrawBackground;
|
||||
private boolean mClipToBounds = false;
|
||||
private boolean mIsUpdated = true;
|
||||
private boolean mForceMountChildrenToView;
|
||||
private float mClipLeft;
|
||||
@@ -82,6 +81,10 @@ import com.facebook.react.views.view.ReactClippingViewGroupHelper;
|
||||
private int mLayoutWidth;
|
||||
private int mLayoutHeight;
|
||||
|
||||
// clip radius
|
||||
float mClipRadius;
|
||||
boolean mClipToBounds = false;
|
||||
|
||||
/* package */ void handleUpdateProperties(ReactStylesDiffMap styles) {
|
||||
if (!mountsToView()) {
|
||||
// Make sure we mount this FlatShadowNode to a View if any of these properties are present.
|
||||
@@ -152,6 +155,11 @@ import com.facebook.react.views.view.ReactClippingViewGroupHelper;
|
||||
mClipToBounds = "hidden".equals(overflow);
|
||||
if (mClipToBounds) {
|
||||
mOverflowsContainer = false;
|
||||
if (mClipRadius > DrawView.MINIMUM_ROUNDED_CLIPPING_VALUE) {
|
||||
// mount to a view if we are overflow: hidden and are clipping, so that we can do one
|
||||
// clipPath to clip all the children of this node (both DrawCommands and Views).
|
||||
forceMountToView();
|
||||
}
|
||||
} else {
|
||||
updateOverflowsContainer();
|
||||
}
|
||||
@@ -483,6 +491,9 @@ import com.facebook.react.views.view.ReactClippingViewGroupHelper;
|
||||
// DrawView anyway, as reactTag is final, and our DrawView instance is the static copy.
|
||||
mDrawView = new DrawView(getReactTag());
|
||||
}
|
||||
|
||||
// avoid path clipping if overflow: visible
|
||||
float clipRadius = mClipToBounds ? mClipRadius : 0.0f;
|
||||
// We have the correct react tag, but we may need a new copy with updated bounds. If the bounds
|
||||
// match or were never set, the same view is returned.
|
||||
mDrawView = mDrawView.collectDrawView(
|
||||
@@ -493,7 +504,8 @@ import com.facebook.react.views.view.ReactClippingViewGroupHelper;
|
||||
clipLeft,
|
||||
clipTop,
|
||||
clipRight,
|
||||
clipBottom);
|
||||
clipBottom,
|
||||
clipRadius);
|
||||
return mDrawView;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user