Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rounded border drawing when border-radius is smaller than border-width #28358

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 45 additions & 4 deletions RNTester/js/examples/View/ViewExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,53 @@ exports.examples = [
},
},
{
title: 'Circle with Border Radius',
title: 'Rounded Borders',
render(): React.Node {
return (
<View
style={{borderRadius: 10, borderWidth: 1, width: 20, height: 20}}
/>
<View style={{flexDirection: 'row'}}>
<View
style={{
width: 50,
height: 50,
borderRadius: 25,
borderWidth: 1,
marginRight: 10,
}}
/>
<View
style={{
width: 50,
height: 50,
borderRadius: 25,
borderWidth: 10,
marginRight: 10,
}}
/>
<View
style={{
width: 50,
height: 50,
borderTopLeftRadius: 5,
borderTopRightRadius: 10,
borderBottomRightRadius: 25,
borderBottomLeftRadius: 50,
borderWidth: 1,
marginRight: 10,
}}
/>
<View
style={{
width: 50,
height: 50,
borderTopLeftRadius: 5,
borderTopRightRadius: 10,
borderBottomRightRadius: 25,
borderBottomLeftRadius: 50,
borderWidth: 10,
marginRight: 10,
}}
/>
</View>
);
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,18 +526,18 @@ private void updatePath() {
mTempRectForBorderRadiusOutline.set(getBounds());
mTempRectForCenterDrawPath.set(getBounds());

float fullBorderWidth = getFullBorderWidth();
if (fullBorderWidth > 0) {
mTempRectForCenterDrawPath.inset(fullBorderWidth * 0.5f, fullBorderWidth * 0.5f);
}

final RectF borderWidth = getDirectionAwareBorderInsets();

mInnerClipTempRectForBorderRadius.top += borderWidth.top;
mInnerClipTempRectForBorderRadius.bottom -= borderWidth.bottom;
mInnerClipTempRectForBorderRadius.left += borderWidth.left;
mInnerClipTempRectForBorderRadius.right -= borderWidth.right;

mTempRectForCenterDrawPath.top += borderWidth.top * 0.5f;
mTempRectForCenterDrawPath.bottom -= borderWidth.bottom * 0.5f;
mTempRectForCenterDrawPath.left += borderWidth.left * 0.5f;
mTempRectForCenterDrawPath.right -= borderWidth.right * 0.5f;

final float borderRadius = getFullBorderRadius();
float topLeftRadius = getBorderRadiusOrDefaultTo(borderRadius, BorderRadiusLocation.TOP_LEFT);
float topRightRadius = getBorderRadiusOrDefaultTo(borderRadius, BorderRadiusLocation.TOP_RIGHT);
Expand Down Expand Up @@ -663,14 +663,22 @@ private void updatePath() {
mCenterDrawPath.addRoundRect(
mTempRectForCenterDrawPath,
new float[] {
innerTopLeftRadiusX + (topLeftRadius > 0 ? extraRadiusForOutline : 0),
innerTopLeftRadiusY + (topLeftRadius > 0 ? extraRadiusForOutline : 0),
innerTopRightRadiusX + (topRightRadius > 0 ? extraRadiusForOutline : 0),
innerTopRightRadiusY + (topRightRadius > 0 ? extraRadiusForOutline : 0),
innerBottomRightRadiusX + (bottomRightRadius > 0 ? extraRadiusForOutline : 0),
innerBottomRightRadiusY + (bottomRightRadius > 0 ? extraRadiusForOutline : 0),
innerBottomLeftRadiusX + (bottomLeftRadius > 0 ? extraRadiusForOutline : 0),
innerBottomLeftRadiusY + (bottomLeftRadius > 0 ? extraRadiusForOutline : 0)
Math.max(topLeftRadius - borderWidth.left * 0.5f,
(borderWidth.left > 0.0f) ? (topLeftRadius / borderWidth.left) : 0.0f),
Math.max(topLeftRadius - borderWidth.top * 0.5f,
(borderWidth.top > 0.0f) ? (topLeftRadius / borderWidth.top) : 0.0f),
Math.max(topRightRadius - borderWidth.right * 0.5f,
(borderWidth.right > 0.0f) ? (topRightRadius / borderWidth.right) : 0.0f),
Math.max(topRightRadius - borderWidth.top * 0.5f,
(borderWidth.top > 0.0f) ? (topRightRadius / borderWidth.top) : 0.0f),
Math.max(bottomRightRadius - borderWidth.right * 0.5f,
(borderWidth.right > 0.0f) ? (bottomRightRadius / borderWidth.right) : 0.0f),
Math.max(bottomRightRadius - borderWidth.bottom * 0.5f,
(borderWidth.bottom > 0.0f) ? (bottomRightRadius / borderWidth.bottom) : 0.0f),
Math.max(bottomLeftRadius - borderWidth.left * 0.5f,
(borderWidth.left > 0.0f) ? (bottomLeftRadius / borderWidth.left) : 0.0f),
Math.max(bottomLeftRadius - borderWidth.bottom * 0.5f,
(borderWidth.bottom > 0.0f) ? (bottomLeftRadius / borderWidth.bottom) : 0.0f)
},
Path.Direction.CW);

Expand Down