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. #1576

Open CarmineRumma opened 6 months ago

CarmineRumma commented 6 months ago

UIGraphicsBeginImageContextWithOptions Patch

husenLogicwind commented 2 months ago

@CarmineRumma I tried to apply this patch and it will not work for me it give me a error Use of undeclared identifier 'image'

Screenshot 2024-04-29 at 12 33 35 PM
qaseemelahi commented 2 months ago

@husenLogicwind I've used following patch my build created but I'm not sure weather its accurate or not @CarmineRumma please verify this.

diff --git a/node_modules/react-native-vector-icons/RNVectorIconsManager/RNVectorIconsManager.m b/node_modules/react-native-vector-icons/RNVectorIconsManager/RNVectorIconsManager.m
index 02a5f49..4ffa62f 100644
--- a/node_modules/react-native-vector-icons/RNVectorIconsManager/RNVectorIconsManager.m
+++ b/node_modules/react-native-vector-icons/RNVectorIconsManager/RNVectorIconsManager.m
@@ -63,13 +63,13 @@ - (BOOL)createAndSaveGlyphImage:(NSString *)glyph withFont:(UIFont *)font
     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 *iconImage = UIGraphicsGetImageFromCurrentImageContext();
-    UIGraphicsEndImageContext();
-
-    NSData *imageData = UIImagePNGRepresentation(iconImage);
+    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
+    UIImage* newImage = [image imageWithRenderingMode: UIImageRenderingModeAlwaysTemplate];
+    UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:iconSize];
+    newImage = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
+      [attributedString drawAtPoint:CGPointMake(0, 0)];
+    }];
+    NSData *imageData = UIImagePNGRepresentation(newImage);
     return [imageData writeToFile:filePath atomically:YES];
   }