File tree Expand file tree Collapse file tree 2 files changed +6
-12
lines changed
packages/react-native/React
Fabric/Mounting/ComponentViews/View Expand file tree Collapse file tree 2 files changed +6
-12
lines changed Original file line number Diff line number Diff line change @@ -826,18 +826,22 @@ - (nonnull instancetype)initWithSize:(CGSize)size format:(nonnull RCTUIGraphicsI
826826}
827827
828828- (nonnull NSImage *)imageWithActions : (NS_NOESCAPE RCTUIGraphicsImageDrawingActions)actions {
829-
830829 NSImage *image = [NSImage imageWithSize: _size
831830 flipped: YES
832831 drawingHandler: ^BOOL (NSRect dstRect) {
833-
834832 RCTUIGraphicsImageRendererContext *context = [NSGraphicsContext currentContext ];
835833 if (self->_format .opaque ) {
836834 CGContextSetAlpha ([context CGContext ], 1.0 );
837835 }
838836 actions (context);
839837 return YES ;
840838 }];
839+
840+ // Force the image to render immediately by locking focus.
841+ // This creates the backing store and makes CGImageForProposedRect work reliably.
842+ [image lockFocus ];
843+ [image unlockFocus ];
844+
841845 return image;
842846}
843847
Original file line number Diff line number Diff line change @@ -872,13 +872,6 @@ static void RCTAddContourEffectToLayer(
872872 layer.contents = (id )image.CGImage ;
873873 layer.contentsScale = image.scale ;
874874#else // [macOS
875- // Force the lazy NSImage to render by locking focus.
876- // NSImage created with imageWithSize:flipped:drawingHandler: is lazy -
877- // the drawing handler isn't called until the image is actually drawn.
878- // We need to force rendering before extracting the CGImage.
879- [image lockFocus ];
880- [image unlockFocus ];
881-
882875 layer.contents = (__bridge id )UIImageGetCGImageRef (image);
883876 layer.contentsScale = UIImageGetScale (image);
884877#endif // macOS]
@@ -1367,10 +1360,7 @@ - (void)invalidateLayer
13671360#else // [macOS
13681361 // Keep a strong reference to the NSImage so that the CGImage it provides
13691362 // (via UIImageGetCGImageRef) remains valid while the layer uses it.
1370- // The image is lazy - force it to render before extracting CGImage.
13711363 _boxShadowImage = boxShadowImage;
1372- [_boxShadowImage lockFocus ];
1373- [_boxShadowImage unlockFocus ];
13741364 _boxShadowLayer.contents = (__bridge id )UIImageGetCGImageRef (_boxShadowImage);
13751365#endif // macOS]
13761366 }
You can’t perform that action at this time.
0 commit comments