Skip to content

Commit 8e21c8e

Browse files
committed
Update RCTBoxShadow to use shim
1 parent f846859 commit 8e21c8e

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

packages/react-native/React/Fabric/Utils/RCTBoxShadow.mm

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,14 @@ static void renderInsetShadows(
288288
CALayer *layer)
289289
{
290290
CGRect boundingRect = RCTGetBoundingRect(shadows, layer.bounds.size);
291-
#if !TARGET_OS_OSX // [macOS]
292-
UIGraphicsImageRendererFormat *const rendererFormat = [UIGraphicsImageRendererFormat defaultFormat];
293-
UIGraphicsImageRenderer *const renderer = [[UIGraphicsImageRenderer alloc] initWithSize:boundingRect.size
294-
format:rendererFormat];
291+
// [macOS Use RCTUIGraphicsImageRenderer shim
292+
RCTUIGraphicsImageRendererFormat *const rendererFormat = [RCTUIGraphicsImageRendererFormat defaultFormat];
293+
RCTUIGraphicsImageRenderer *const renderer = [[RCTUIGraphicsImageRenderer alloc] initWithSize:boundingRect.size
294+
format:rendererFormat];
295+
// macOS]
296+
295297
UIImage *const boxShadowImage =
296-
[renderer imageWithActions:^(UIGraphicsImageRendererContext *_Nonnull rendererContext) {
298+
[renderer imageWithActions:^(RCTUIGraphicsImageRendererContext *_Nonnull rendererContext) { // [macOS]
297299
auto [outsetShadows, insetShadows] = splitBoxShadowsByInset(shadows);
298300
const CGContextRef context = rendererContext.CGContext;
299301
// Outset shadows should be before inset shadows since outset needs to
@@ -303,22 +305,6 @@ static void renderInsetShadows(
303305
renderOutsetShadows(outsetShadows, cornerRadii, layer, boundingRect, context);
304306
renderInsetShadows(insetShadows, cornerRadii, edgeInsets, layer, boundingRect, context);
305307
}];
306-
#else // [macOS
307-
UIGraphicsBeginImageContextWithOptions(boundingRect.size, YES, 0.0);
308-
CGContextRef context = UIGraphicsGetCurrentContext();
309-
310-
// Mostly copied from above iOS block
311-
auto [outsetShadows, insetShadows] = splitBoxShadowsByInset(shadows);
312-
// Outset shadows should be before inset shadows since outset needs to
313-
// clear out a region in the view so we do not block its contents.
314-
// Inset shadows could draw over those outset shadows but if the shadow
315-
// colors have alpha < 1 then we will have inaccurate alpha compositing
316-
renderOutsetShadows(outsetShadows, cornerRadii, layer, boundingRect, context);
317-
renderInsetShadows(insetShadows, cornerRadii, edgeInsets, layer, boundingRect, context);
318-
319-
UIImage *boxShadowImage = UIGraphicsGetImageFromCurrentImageContext();
320-
UIGraphicsEndImageContext();
321-
#endif // macOS]
322308

323309
return boxShadowImage;
324310
}

0 commit comments

Comments
 (0)