Skip to content

Commit da10ad1

Browse files
jorge-cabfacebook-github-bot
authored andcommitted
Fix visual artifacts when sometimes using decimal assymetric borderRadii (#54237)
Summary: Before we were adding a single pixel for the stretchable area. in RCTViewComponentView we calculate what percentage is 1 pixel from the entire image to create the unit rectangle: ``` CGRect contentsCenter = CGRect{ CGPoint{imageCapInsets.left / imageSize.width, imageCapInsets.top / imageSize.height}, CGSize{(CGFloat)1.0 / imageSize.width, (CGFloat)1.0 / imageSize.height}}; ``` However sometimes when dividing `1.0 / imageSize.width` we would get a big enough float that causes a rounding error essentially having part of the border bleed into the stretchable region. The easiest way to fix this is give the stretchable region a little more space so to prevent the bleeding. We can do this by rounding the edgeInsets that give the border area its size The alternative is some shockingly complex math to appropriately calculate the most convenient stretchable area size Changelog: [Internal] Reviewed By: cipolleschi Differential Revision: D85260693
1 parent 2810128 commit da10ad1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/react-native/React/Views/RCTBorderDrawing.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,12 @@ static CGPathRef RCTPathCreateOuterOutline(BOOL drawToEdge, CGRect rect, RCTCorn
247247

248248
const CGSize size = makeStretchable ? (CGSize){
249249
// 1pt for the middle stretchable area along each axis
250-
edgeInsets.left + 1 + edgeInsets.right,
251-
edgeInsets.top + 1 + edgeInsets.bottom
250+
// we also need to round the edge insets to avoid border bleeding
251+
// this is because if the size is decimal, when calculating the unit
252+
// rectangle for CALayer.contentsCenter we encounter rounding errors
253+
// which causes visual glitches
254+
ceil(edgeInsets.left) + 1 + ceil(edgeInsets.right),
255+
ceil(edgeInsets.top) + 1 + ceil(edgeInsets.bottom),
252256
} : viewSize;
253257

254258
UIGraphicsImageRenderer *const imageRenderer =

0 commit comments

Comments
 (0)