From a2e1ed8f31c9687c5ed6c7fddb507b4d67835dca Mon Sep 17 00:00:00 2001 From: loumzy Date: Fri, 17 Nov 2023 15:42:50 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=20fix=20bug=EF=BC=8C=20to=20avoid=20c?= =?UTF-8?q?rashing=20the=20system=20when=20passing=200=20as=20a=20paramete?= =?UTF-8?q?r=20to=20UIGraphicsBeginImageContextWithOptions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m | 8 +++++++- ios/sdk/WeexSDK/Sources/Model/WXComponent.mm | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m b/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m index 2251731598..82b0226e6c 100644 --- a/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m +++ b/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m @@ -145,6 +145,9 @@ - (WXDisplayBlock)_displayBlock __strong WXComponent* sself = wself; if (sself) { + CGFloat width = bounds.size.width ?: 1; + CGFloat height = bounds.size.height ?: 1; + CGSize size = CGSizeMake(width, height); UIGraphicsBeginImageContextWithOptions(bounds.size, [sself _bitmapOpaqueWithSize:bounds.size] , 0.0); UIImage *image = [sself drawRect:bounds]; if (!image) { @@ -259,7 +262,10 @@ - (void)triggerDisplay - (CGContextRef)beginDrawContext:(CGRect)bounds { - UIGraphicsBeginImageContextWithOptions(bounds.size, [self _bitmapOpaqueWithSize:bounds.size], 0.0); + CGFloat width = bounds.size.width ?: 1; + CGFloat height = bounds.size.height ?: 1; + CGSize size = CGSizeMake(width, height); + UIGraphicsBeginImageContextWithOptions(size, [self _bitmapOpaqueWithSize:size], 0.0); CGContextRef context = UIGraphicsGetCurrentContext(); // float scaleFactor = [[UIScreen mainScreen] scale]; diff --git a/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm b/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm index a2dab80e94..96ffcd62da 100644 --- a/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm +++ b/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm @@ -953,7 +953,10 @@ - (void)_configWXComponentA11yWithAttributes:(NSDictionary *)attributes - (UIImage *)imageFromLayer:(CALayer *)layer { - UIGraphicsBeginImageContextWithOptions(layer.frame.size, NO, 0); + CGFloat width = layer.frame.size.width ?: 1; + CGFloat height = layer.frame.size.height ?: 1; + CGSize size = CGSizeMake(width, height); + UIGraphicsBeginImageContextWithOptions(size, NO, 0); [layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();