feat: add macos back to Example app (#2119)

PR restoring macos CI job and restoring usage of UIGraphicsBeginImageContextWithOptions on macos since there is no implementation for UIGraphicsImageRendererFormat there yet.
This commit is contained in:
Wojciech Lewicki
2023-08-24 12:07:27 +02:00
committed by GitHub
parent fb28d7809c
commit 7e514d7232
25 changed files with 3467 additions and 32 deletions
+12 -3
View File
@@ -323,18 +323,27 @@ using namespace facebook::react;
- (NSString *)getDataURLWithBounds:(CGRect)bounds
{
#if !TARGET_OS_OSX // [macOS]
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:bounds.size];
UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext *_Nonnull rendererContext) {
#else // [macOS
UIGraphicsBeginImageContextWithOptions(bounds.size, NO, 1);
#endif // macOS]
[self clearChildCache];
[self drawRect:bounds];
[self clearChildCache];
[self invalidate];
#if !TARGET_OS_OSX // [macOS]
}];
#endif
#if !TARGET_OS_OSX // [macOS]
NSData *imageData = UIImagePNGRepresentation(image);
NSString *base64 = [imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
#else // [macOS
NSData *imageData = UIImagePNGRepresentation(UIGraphicsGetImageFromCurrentImageContext());
NSString *base64 = [imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
UIGraphicsEndImageContext();
#endif // macOS]
return base64;
}
+32
View File
@@ -304,6 +304,7 @@ UInt32 saturate(CGFloat value)
CGContextRelease(bcontext);
free(pixels);
#if !TARGET_OS_OSX // [macOS]
UIGraphicsImageRendererFormat *format = [UIGraphicsImageRendererFormat defaultFormat];
format.scale = scale;
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:boundsSize format:format];
@@ -328,6 +329,37 @@ UInt32 saturate(CGFloat value)
// Render blended result into current render context
CGImageRelease(maskImage);
#else // [macOS
// Render content of current SVG Renderable to image
UIGraphicsBeginImageContextWithOptions(boundsSize, NO, 0.0);
CGContextRef newContext = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(newContext, 0.0, height);
CGContextScaleCTM(newContext, 1.0, -1.0);
[self renderLayerTo:newContext rect:rect];
CGImageRef contentImage = CGBitmapContextCreateImage(newContext);
UIGraphicsEndImageContext();
// Blend current element and mask
UIGraphicsBeginImageContextWithOptions(boundsSize, NO, 0.0);
newContext = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(newContext, 0.0, height);
CGContextScaleCTM(newContext, 1.0, -1.0);
CGContextSetBlendMode(newContext, kCGBlendModeCopy);
CGContextDrawImage(newContext, drawBounds, maskImage);
CGImageRelease(maskImage);
CGContextSetBlendMode(newContext, kCGBlendModeSourceIn);
CGContextDrawImage(newContext, drawBounds, contentImage);
CGImageRelease(contentImage);
CGImageRef blendedImage = CGBitmapContextCreateImage(newContext);
UIGraphicsEndImageContext();
// Render blended result into current render context
CGContextDrawImage(context, drawBounds, blendedImage);
CGImageRelease(blendedImage);
#endif // macOS]
} else {
[self renderLayerTo:context rect:rect];
}