react-native-vector-icons icon indicating copy to clipboard operation
react-native-vector-icons copied to clipboard

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

Open CarmineRumma opened this issue 2 years ago • 2 comments

UIGraphicsBeginImageContextWithOptions Patch

CarmineRumma avatar Dec 07 '23 08:12 CarmineRumma

@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

husenLogicwind avatar Apr 29 '24 07:04 husenLogicwind

@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];
   }
 

qaseemelahi avatar Apr 29 '24 11:04 qaseemelahi