Skip to content

Commit 3614f20

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 Differential Revision: D85260693
1 parent b823b26 commit 3614f20

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
@@ -248,8 +248,12 @@ static CGPathRef RCTPathCreateOuterOutline(BOOL drawToEdge, CGRect rect, RCTCorn
248248

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

255259
UIGraphicsImageRenderer *const imageRenderer =

0 commit comments

Comments
 (0)