oblador / react-native-vector-icons

Customizable Icons for React Native with support for image source and full styling.
https://oblador.github.io/react-native-vector-icons/
MIT License
17.31k stars 2.12k forks source link

Crashes the app, as IOS has deprecated UIGraphicsBeginImageContextWithOptions from IOS 17. #1575

Open CarmineRumma opened 6 months ago

CarmineRumma commented 6 months ago

Environment

[iOS] react-native-vector-icons: 10.0.2

Description

Crashes the app, as IOS has deprecated UIGraphicsBeginImageContextWithOptions from IOS 17.

Patch

diff --git a/RNVectorIconsManager/RNVectorIconsManager.mm b/RNVectorIconsManager/RNVectorIconsManager.mm
index 73b94c4..99bd769 100644
--- a/RNVectorIconsManager/RNVectorIconsManager.mm
+++ b/RNVectorIconsManager/RNVectorIconsManager.mm
@@ -62,15 +62,15 @@ - (BOOL)createAndSaveGlyphImage:(NSString *)glyph withFont:(UIFont *)font
     // No cached icon exists, we need to create it and persist to disk

     NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:glyph attributes:@{NSFontAttributeName: font, NSForegroundColorAttributeName: color}];
-
     CGSize iconSize = [attributedString size];
-    UIGraphicsBeginImageContextWithOptions(iconSize, NO, 0.0);
-    [attributedString drawAtPoint:CGPointMake(0, 0)];
+    UIImage* newImage = [image imageWithRenderingMode: UIImageRenderingModeAlwaysTemplate];

-    UIImage *iconImage = UIGraphicsGetImageFromCurrentImageContext();
-    UIGraphicsEndImageContext();
+    UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:iconSize];
+    newImage = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
+      [attributedString drawAtPoint:CGPointMake(0, 0)];
+    }];

-    NSData *imageData = UIImagePNGRepresentation(iconImage);
+    NSData *imageData = UIImagePNGRepresentation(newImage);
     return [imageData writeToFile:filePath atomically:YES];
   }