Skip to content

Commit

Permalink
Update RCTBoxShadow to use shim
Browse files Browse the repository at this point in the history
  • Loading branch information
Saadnajmi committed Oct 4, 2024
1 parent f846859 commit 8e21c8e
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions packages/react-native/React/Fabric/Utils/RCTBoxShadow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,14 @@ static void renderInsetShadows(
CALayer *layer)
{
CGRect boundingRect = RCTGetBoundingRect(shadows, layer.bounds.size);
#if !TARGET_OS_OSX // [macOS]
UIGraphicsImageRendererFormat *const rendererFormat = [UIGraphicsImageRendererFormat defaultFormat];
UIGraphicsImageRenderer *const renderer = [[UIGraphicsImageRenderer alloc] initWithSize:boundingRect.size
format:rendererFormat];
// [macOS Use RCTUIGraphicsImageRenderer shim
RCTUIGraphicsImageRendererFormat *const rendererFormat = [RCTUIGraphicsImageRendererFormat defaultFormat];
RCTUIGraphicsImageRenderer *const renderer = [[RCTUIGraphicsImageRenderer alloc] initWithSize:boundingRect.size
format:rendererFormat];
// macOS]

UIImage *const boxShadowImage =
[renderer imageWithActions:^(UIGraphicsImageRendererContext *_Nonnull rendererContext) {
[renderer imageWithActions:^(RCTUIGraphicsImageRendererContext *_Nonnull rendererContext) { // [macOS]
auto [outsetShadows, insetShadows] = splitBoxShadowsByInset(shadows);
const CGContextRef context = rendererContext.CGContext;
// Outset shadows should be before inset shadows since outset needs to
Expand All @@ -303,22 +305,6 @@ static void renderInsetShadows(
renderOutsetShadows(outsetShadows, cornerRadii, layer, boundingRect, context);
renderInsetShadows(insetShadows, cornerRadii, edgeInsets, layer, boundingRect, context);
}];
#else // [macOS
UIGraphicsBeginImageContextWithOptions(boundingRect.size, YES, 0.0);
CGContextRef context = UIGraphicsGetCurrentContext();

// Mostly copied from above iOS block
auto [outsetShadows, insetShadows] = splitBoxShadowsByInset(shadows);
// Outset shadows should be before inset shadows since outset needs to
// clear out a region in the view so we do not block its contents.
// Inset shadows could draw over those outset shadows but if the shadow
// colors have alpha < 1 then we will have inaccurate alpha compositing
renderOutsetShadows(outsetShadows, cornerRadii, layer, boundingRect, context);
renderInsetShadows(insetShadows, cornerRadii, edgeInsets, layer, boundingRect, context);

UIImage *boxShadowImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
#endif // macOS]

return boxShadowImage;
}

0 comments on commit 8e21c8e

Please sign in to comment.