Fix case where certain spreads break box shadow logic (#45746)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45746

Once the spread was past a certain value, it could break some of this logic by creating a null rect or negative size. This just makes it so that in those cases, inset will be a 0x0 clear region rect and outset will be nothing

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D60317780

fbshipit-source-id: 021bf41d71ae69809076b4f5e6413d04cd878372
This commit is contained in:
Joe Vilches
2024-07-31 10:13:20 -07:00
committed by Facebook GitHub Bot
parent 49a7a7d58b
commit acb634bc96
@@ -117,8 +117,8 @@ static void renderOutsetShadows(
// the blur radius since this rect is not the shadow itself.
const RCTCornerInsets shadowRectCornerInsets =
RCTGetCornerInsets(cornerRadiiForBoxShadow(cornerRadii, spreadDistance), UIEdgeInsetsZero);
CGSize shadowRectSize =
CGSizeMake(layer.bounds.size.width + 2 * spreadDistance, layer.bounds.size.height + 2 * spreadDistance);
CGSize shadowRectSize = CGSizeMake(
fmax(layer.bounds.size.width + 2 * spreadDistance, 0), fmax(layer.bounds.size.height + 2 * spreadDistance, 0));
// Ensure this is drawn offscreen and will not show in the image
CGRect shadowRect = CGRectMake(-shadowRectSize.width, 0, shadowRectSize.width, shadowRectSize.height);
CGPathRef shadowRectPath = RCTPathCreateWithRoundedRect(shadowRect, shadowRectCornerInsets, nil);
@@ -222,6 +222,11 @@ static void renderInsetShadows(
// of the view.
CGRect shadowCastingRect = CGRectInset(shadowFrame, -blurRadius, -blurRadius);
CGRect clearRegionRect = CGRectInset(shadowFrame, spreadDistance, spreadDistance);
// This happens if the spread causes the height/width to be negative. A null
// rect breaks a lot of the logic, so lets just keep it as a point
if (CGRectIsNull(clearRegionRect)) {
clearRegionRect = CGRectMake(0, 0, 0, 0);
}
CGPoint offsetToMoveOffscreen = CGPointMake(
-fmax(
shadowCastingRect.size.width,