mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-02 23:02:16 +00:00
feat: remove UIGraphicsBeginImageContextWithOptions from repo (#2117)
Since UIGraphicsBeginImageContextWithOptions will be depracated in iOS 17 (developer.apple.com/documentation/uikit/1623912-uigraphicsbeginimagecontextwitho), I changed the implementation to not use it and use UIGraphicsImageRenderer instead. Also added Mask examples to be able to test it.
This commit is contained in:
@@ -63,9 +63,7 @@
|
||||
|
||||
- (RNSVGNode *)getDefinedMask:(NSString *)maskName;
|
||||
|
||||
- (NSString *)getDataURL;
|
||||
|
||||
- (NSString *)getDataURLwithBounds:(CGRect)bounds;
|
||||
- (NSString *)getDataURLWithBounds:(CGRect)bounds;
|
||||
|
||||
- (CGRect)getContextBounds;
|
||||
|
||||
|
||||
@@ -321,29 +321,20 @@ using namespace facebook::react;
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSString *)getDataURL
|
||||
- (NSString *)getDataURLWithBounds:(CGRect)bounds
|
||||
{
|
||||
UIGraphicsBeginImageContextWithOptions(_boundingBox.size, NO, 0);
|
||||
[self clearChildCache];
|
||||
[self drawRect:_boundingBox];
|
||||
[self clearChildCache];
|
||||
[self invalidate];
|
||||
NSData *imageData = UIImagePNGRepresentation(UIGraphicsGetImageFromCurrentImageContext());
|
||||
NSString *base64 = [imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
|
||||
UIGraphicsEndImageContext();
|
||||
return base64;
|
||||
}
|
||||
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:bounds.size];
|
||||
|
||||
- (NSString *)getDataURLwithBounds:(CGRect)bounds
|
||||
{
|
||||
UIGraphicsBeginImageContextWithOptions(bounds.size, NO, 1);
|
||||
[self clearChildCache];
|
||||
[self drawRect:bounds];
|
||||
[self clearChildCache];
|
||||
[self invalidate];
|
||||
NSData *imageData = UIImagePNGRepresentation(UIGraphicsGetImageFromCurrentImageContext());
|
||||
UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext *_Nonnull rendererContext) {
|
||||
[self clearChildCache];
|
||||
[self drawRect:bounds];
|
||||
[self clearChildCache];
|
||||
[self invalidate];
|
||||
}];
|
||||
|
||||
NSData *imageData = UIImagePNGRepresentation(image);
|
||||
NSString *base64 = [imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
|
||||
UIGraphicsEndImageContext();
|
||||
|
||||
return base64;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user