Skip to content

Commit 28dce36

Browse files
IjzerenHeinfacebook-github-bot
authored andcommitted
Fix rounded border drawing when border-radius is smaller than border-width (#28358)
Summary: This PR fixes the drawing of the border rounded edges when the border-radius is small than the border-width. The current implementation capped the possible border-radius making it impossible to set smaller border-radii when using thicker borders. After inspection it was found that the rounded-rect calculation is incorrect. ## Changelog `[Android] [Fixed] - Fix rounded border-drawing when border-radius is smaller than border-width` Pull Request resolved: #28358 Test Plan: **Faulty situation:** As you can see, when the border-radius becomes very low, the border is stuck at a minimum value. Only after setting the border-radius fully to 0 is it again rendered correctly. ![ezgif com-video-to-gif (2)](https://user-images.githubusercontent.com/6184593/77183540-c3435b00-6ace-11ea-950d-29a0ea1757bd.gif) **After the fix:** ![ezgif com-video-to-gif (3)](https://user-images.githubusercontent.com/6184593/77183619-e837ce00-6ace-11ea-93a5-910127d352b7.gif) Differential Revision: D21124739 Pulled By: shergin fbshipit-source-id: cefd1776b77b5b9fb335e95fd7fdd7f345579dc4
1 parent 5dc6ede commit 28dce36

File tree

2 files changed

+66
-17
lines changed

2 files changed

+66
-17
lines changed

RNTester/js/examples/View/ViewExample.js

+45-4
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,53 @@ exports.examples = [
148148
},
149149
},
150150
{
151-
title: 'Circle with Border Radius',
151+
title: 'Rounded Borders',
152152
render(): React.Node {
153153
return (
154-
<View
155-
style={{borderRadius: 10, borderWidth: 1, width: 20, height: 20}}
156-
/>
154+
<View style={{flexDirection: 'row'}}>
155+
<View
156+
style={{
157+
width: 50,
158+
height: 50,
159+
borderRadius: 25,
160+
borderWidth: 1,
161+
marginRight: 10,
162+
}}
163+
/>
164+
<View
165+
style={{
166+
width: 50,
167+
height: 50,
168+
borderRadius: 25,
169+
borderWidth: 10,
170+
marginRight: 10,
171+
}}
172+
/>
173+
<View
174+
style={{
175+
width: 50,
176+
height: 50,
177+
borderTopLeftRadius: 5,
178+
borderTopRightRadius: 10,
179+
borderBottomRightRadius: 25,
180+
borderBottomLeftRadius: 50,
181+
borderWidth: 1,
182+
marginRight: 10,
183+
}}
184+
/>
185+
<View
186+
style={{
187+
width: 50,
188+
height: 50,
189+
borderTopLeftRadius: 5,
190+
borderTopRightRadius: 10,
191+
borderBottomRightRadius: 25,
192+
borderBottomLeftRadius: 50,
193+
borderWidth: 10,
194+
marginRight: 10,
195+
}}
196+
/>
197+
</View>
157198
);
158199
},
159200
},

ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewBackgroundDrawable.java

+21-13
Original file line numberDiff line numberDiff line change
@@ -526,18 +526,18 @@ private void updatePath() {
526526
mTempRectForBorderRadiusOutline.set(getBounds());
527527
mTempRectForCenterDrawPath.set(getBounds());
528528

529-
float fullBorderWidth = getFullBorderWidth();
530-
if (fullBorderWidth > 0) {
531-
mTempRectForCenterDrawPath.inset(fullBorderWidth * 0.5f, fullBorderWidth * 0.5f);
532-
}
533-
534529
final RectF borderWidth = getDirectionAwareBorderInsets();
535530

536531
mInnerClipTempRectForBorderRadius.top += borderWidth.top;
537532
mInnerClipTempRectForBorderRadius.bottom -= borderWidth.bottom;
538533
mInnerClipTempRectForBorderRadius.left += borderWidth.left;
539534
mInnerClipTempRectForBorderRadius.right -= borderWidth.right;
540535

536+
mTempRectForCenterDrawPath.top += borderWidth.top * 0.5f;
537+
mTempRectForCenterDrawPath.bottom -= borderWidth.bottom * 0.5f;
538+
mTempRectForCenterDrawPath.left += borderWidth.left * 0.5f;
539+
mTempRectForCenterDrawPath.right -= borderWidth.right * 0.5f;
540+
541541
final float borderRadius = getFullBorderRadius();
542542
float topLeftRadius = getBorderRadiusOrDefaultTo(borderRadius, BorderRadiusLocation.TOP_LEFT);
543543
float topRightRadius = getBorderRadiusOrDefaultTo(borderRadius, BorderRadiusLocation.TOP_RIGHT);
@@ -663,14 +663,22 @@ private void updatePath() {
663663
mCenterDrawPath.addRoundRect(
664664
mTempRectForCenterDrawPath,
665665
new float[] {
666-
innerTopLeftRadiusX + (topLeftRadius > 0 ? extraRadiusForOutline : 0),
667-
innerTopLeftRadiusY + (topLeftRadius > 0 ? extraRadiusForOutline : 0),
668-
innerTopRightRadiusX + (topRightRadius > 0 ? extraRadiusForOutline : 0),
669-
innerTopRightRadiusY + (topRightRadius > 0 ? extraRadiusForOutline : 0),
670-
innerBottomRightRadiusX + (bottomRightRadius > 0 ? extraRadiusForOutline : 0),
671-
innerBottomRightRadiusY + (bottomRightRadius > 0 ? extraRadiusForOutline : 0),
672-
innerBottomLeftRadiusX + (bottomLeftRadius > 0 ? extraRadiusForOutline : 0),
673-
innerBottomLeftRadiusY + (bottomLeftRadius > 0 ? extraRadiusForOutline : 0)
666+
Math.max(topLeftRadius - borderWidth.left * 0.5f,
667+
(borderWidth.left > 0.0f) ? (topLeftRadius / borderWidth.left) : 0.0f),
668+
Math.max(topLeftRadius - borderWidth.top * 0.5f,
669+
(borderWidth.top > 0.0f) ? (topLeftRadius / borderWidth.top) : 0.0f),
670+
Math.max(topRightRadius - borderWidth.right * 0.5f,
671+
(borderWidth.right > 0.0f) ? (topRightRadius / borderWidth.right) : 0.0f),
672+
Math.max(topRightRadius - borderWidth.top * 0.5f,
673+
(borderWidth.top > 0.0f) ? (topRightRadius / borderWidth.top) : 0.0f),
674+
Math.max(bottomRightRadius - borderWidth.right * 0.5f,
675+
(borderWidth.right > 0.0f) ? (bottomRightRadius / borderWidth.right) : 0.0f),
676+
Math.max(bottomRightRadius - borderWidth.bottom * 0.5f,
677+
(borderWidth.bottom > 0.0f) ? (bottomRightRadius / borderWidth.bottom) : 0.0f),
678+
Math.max(bottomLeftRadius - borderWidth.left * 0.5f,
679+
(borderWidth.left > 0.0f) ? (bottomLeftRadius / borderWidth.left) : 0.0f),
680+
Math.max(bottomLeftRadius - borderWidth.bottom * 0.5f,
681+
(borderWidth.bottom > 0.0f) ? (bottomLeftRadius / borderWidth.bottom) : 0.0f)
674682
},
675683
Path.Direction.CW);
676684

0 commit comments

Comments
 (0)