Skip to content

Commit

Permalink
Prefer new imageWithTintColor API when tinting an UIImage (#5458)
Browse files Browse the repository at this point in the history
With this change, dynamic colors will be supported when tinting an image and the image color will change on the fly depending on the dynamic provider and traits. This will be especially useful when supporting the new dark mode in iOS 13.
  • Loading branch information
danilobuerger authored and guyca committed Sep 9, 2019
1 parent bac0a88 commit 5d751f6
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/ios/UIImage+tint.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ @implementation UIImage (tint)

- (UIImage *)withTintColor:(UIColor *)color {
UIImage *newImage = [self imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
if (@available(iOS 13.0, *)) {
return [newImage imageWithTintColor:color];
}
#endif
UIGraphicsBeginImageContextWithOptions(self.size, NO, newImage.scale);
[color set];
[newImage drawInRect:CGRectMake(0, 0, self.size.width, newImage.size.height)];
Expand Down

1 comment on commit 5d751f6

@eladgel
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this commit tested on RN 0.59.9? I've checked this multiple times and it does not work, the color stays blue

Please sign in to comment.