From ce518a85e499abdd2ba18c38737011a36b3cb095 Mon Sep 17 00:00:00 2001 From: xplor-peter <112909847+xplor-peter@users.noreply.github.com> Date: Thu, 24 Aug 2023 12:16:31 +1000 Subject: [PATCH] PES-5714: replace UIGraphicsBeginImageContextWithOptions (#3) --- .../src/MDCTextInputControllerLegacyDefault.m | 14 ++++++++------ .../src/MDCTextInputControllerLegacyFullWidth.m | 12 +++++++----- .../src/private/MDCTextInputCommonFundament.m | 12 ++++++------ 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/components/TextFields/src/MDCTextInputControllerLegacyDefault.m b/components/TextFields/src/MDCTextInputControllerLegacyDefault.m index 1036184760e..8a726e834ae 100644 --- a/components/TextFields/src/MDCTextInputControllerLegacyDefault.m +++ b/components/TextFields/src/MDCTextInputControllerLegacyDefault.m @@ -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; diff --git a/components/TextFields/src/MDCTextInputControllerLegacyFullWidth.m b/components/TextFields/src/MDCTextInputControllerLegacyFullWidth.m index da2ffb3e1d0..1286c4f2a3d 100644 --- a/components/TextFields/src/MDCTextInputControllerLegacyFullWidth.m +++ b/components/TextFields/src/MDCTextInputControllerLegacyFullWidth.m @@ -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; diff --git a/components/TextFields/src/private/MDCTextInputCommonFundament.m b/components/TextFields/src/private/MDCTextInputCommonFundament.m index 5fc4cb0eda7..fcb17e3826a 100644 --- a/components/TextFields/src/private/MDCTextInputCommonFundament.m +++ b/components/TextFields/src/private/MDCTextInputCommonFundament.m @@ -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;