Skip to content

Commit

Permalink
PES-5714: replace UIGraphicsBeginImageContextWithOptions (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
xplor-peter authored Aug 24, 2023
1 parent cf50992 commit ce518a8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
14 changes: 8 additions & 6 deletions components/TextFields/src/MDCTextInputControllerLegacyDefault.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ - (UIImage *)drawnClearButtonImage:(UIColor *)color {

CGFloat scale = [UIScreen mainScreen].scale;
CGRect bounds = CGRectMake(0, 0, clearButtonSize.width * scale, clearButtonSize.height * scale);
UIGraphicsBeginImageContextWithOptions(bounds.size, false, scale);
[color setFill];

[MDCPathForClearButtonLegacyImageFrame(bounds) fill];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
format.scale = scale;
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:bounds.size format:format];
UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
[color setFill];

[MDCPathForClearButtonLegacyImageFrame(bounds) fill];
}];

image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
return image;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ - (UIImage *)drawnClearButtonImage:(UIColor *)color {

CGFloat scale = [UIScreen mainScreen].scale;
CGRect bounds = CGRectMake(0, 0, clearButtonSize.width * scale, clearButtonSize.height * scale);
UIGraphicsBeginImageContextWithOptions(bounds.size, false, scale);
[color setFill];
UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init];
format.scale = scale;
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:bounds.size format:format];
UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
[color setFill];

[MDCPathForClearButtonLegacyImageFrame(bounds) fill];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[MDCPathForClearButtonLegacyImageFrame(bounds) fill];
}];

image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
return image;
Expand Down
12 changes: 6 additions & 6 deletions components/TextFields/src/private/MDCTextInputCommonFundament.m
Original file line number Diff line number Diff line change
Expand Up @@ -627,12 +627,12 @@ - (UIImage *)drawnClearButtonImage {
MDCTextInputClearButtonImageSquareWidthHeight);

CGRect bounds = CGRectMake(0, 0, clearButtonSize.width, clearButtonSize.height);
UIGraphicsBeginImageContextWithOptions(bounds.size, false, 0);
[UIColor.grayColor setFill];

[MDCPathForClearButtonImageFrame(bounds) fill];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:bounds.size];
UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) {
[UIColor.grayColor setFill];
[MDCPathForClearButtonImageFrame(bounds) fill];
}];

image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
return image;
Expand Down

0 comments on commit ce518a8

Please sign in to comment.