# Summary

On `react-native-macos` 0.76, `UIGraphicsBeginImageContextWithOptions`
and some other UIGraphics directives were removed so the temporary
solution is to copy the removed functions here.

More details
here https://github.com/software-mansion/react-native-svg/issues/2528
and here https://github.com/microsoft/react-native-macos/pull/2209

Closes #2528

## Test Plan

Built the `fabric-macos-example` for with `react-native-macos@0.76.0`

## Compatibility

| OS      | Implemented |
| ------- | :---------: |
| MacOS   |          |

## Checklist

- [x] I have tested this on a device and a simulator
This commit is contained in:
Jakub Grzywacz
2024-11-13 12:30:05 +01:00
committed by GitHub
parent d0530e4b9f
commit 1256d561df
19 changed files with 2965 additions and 2131 deletions
+7 -3
View File
@@ -19,6 +19,10 @@
#import "RNSVGFabricConversions.h"
#endif // RCT_NEW_ARCH_ENABLED
#if TARGET_OS_OSX // [macOS
#import "RNSVGUIKit.h"
#endif // macOS]
@implementation RNSVGSvgView {
NSMutableDictionary<NSString *, RNSVGNode *> *_clipPaths;
NSMutableDictionary<NSString *, RNSVGNode *> *_templates;
@@ -368,7 +372,7 @@ using namespace facebook::react;
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:bounds.size];
UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext *_Nonnull rendererContext) {
#else // [macOS
UIGraphicsBeginImageContextWithOptions(bounds.size, NO, 1);
RNSVGUIGraphicsBeginImageContextWithOptions(bounds.size, NO, 1);
#endif // macOS]
[self clearChildCache];
[self drawRect:bounds];
@@ -381,9 +385,9 @@ using namespace facebook::react;
NSData *imageData = UIImagePNGRepresentation(image);
NSString *base64 = [imageData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
#else // [macOS
NSData *imageData = UIImagePNGRepresentation(UIGraphicsGetImageFromCurrentImageContext());
NSData *imageData = UIImagePNGRepresentation(RNSVGUIGraphicsGetImageFromCurrentImageContext());
NSString *base64 = [imageData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
UIGraphicsEndImageContext();
RNSVGUIGraphicsEndImageContext();
#endif // macOS]
return base64;
}