From d62303baf017a8ef9dede962e586c1b8d26a39f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Tue, 7 Sep 2021 10:46:27 +0800 Subject: [PATCH] iOS: fix quickly set image url caused image integrity error --- doric-iOS/Pod/Classes/Shader/DoricImageNode.m | 63 ++++++++++--------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/doric-iOS/Pod/Classes/Shader/DoricImageNode.m b/doric-iOS/Pod/Classes/Shader/DoricImageNode.m index 9991baff..1cd96fd6 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricImageNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricImageNode.m @@ -28,6 +28,7 @@ #if __has_include() #import +#import @interface DoricImageView : YYAnimatedImageView @end @@ -236,38 +237,42 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id __block BOOL async = NO; view.doricLayout.undefined = YES; #if __has_include() - [view yy_setImageWithURL:[NSURL URLWithString:prop] placeholder:[self currentPlaceHolderImage] options:0 completion:^(UIImage *image, NSURL *url, YYWebImageFromType from, YYWebImageStage stage, NSError *error) { - __strong typeof(_self) self = _self; - if (self.placeHolderColor || self.errorColor) { - self.view.contentMode = self.contentMode; - } - self.view.doricLayout.undefined = NO; - if (error) { - [[self currentErrorImage] also:^(UIImage *it) { - self.view.image = it; - }]; - if (self.loadCallbackId.length > 0) { - [self callJSResponse:self.loadCallbackId, nil]; + dispatch_async([_YYWebImageSetter setterQueue], ^{ + [view yy_cancelCurrentImageRequest]; + + [view yy_setImageWithURL:[NSURL URLWithString:prop] placeholder:[self currentPlaceHolderImage] options:0 completion:^(UIImage *image, NSURL *url, YYWebImageFromType from, YYWebImageStage stage, NSError *error) { + __strong typeof(_self) self = _self; + if (self.placeHolderColor || self.errorColor) { + self.view.contentMode = self.contentMode; } - } else if (image && stage == YYWebImageStageFinished) { - if (image.scale != self.imageScale) { - image = [YYImage imageWithCGImage:image.CGImage scale:self.imageScale orientation:image.imageOrientation]; - self.view.image = image; - } - if (self.loadCallbackId.length > 0) { - [self callJSResponse:self.loadCallbackId, - @{@"width": @(image.size.width), @"height": @(image.size.height)}, - nil]; - } - if (async) { - DoricSuperNode *node = self.superNode; - while (node.superNode != nil) { - node = node.superNode; + self.view.doricLayout.undefined = NO; + if (error) { + [[self currentErrorImage] also:^(UIImage *it) { + self.view.image = it; + }]; + if (self.loadCallbackId.length > 0) { + [self callJSResponse:self.loadCallbackId, nil]; + } + } else if (image && stage == YYWebImageStageFinished) { + if (image.scale != self.imageScale) { + image = [YYImage imageWithCGImage:image.CGImage scale:self.imageScale orientation:image.imageOrientation]; + self.view.image = image; + } + if (self.loadCallbackId.length > 0) { + [self callJSResponse:self.loadCallbackId, + @{@"width": @(image.size.width), @"height": @(image.size.height)}, + nil]; + } + if (async) { + DoricSuperNode *node = self.superNode; + while (node.superNode != nil) { + node = node.superNode; + } + [node requestLayout]; } - [node requestLayout]; } - } - }]; + }]; + }); #elif __has_include() [view sd_setImageWithURL:[NSURL URLWithString:prop] placeholderImage:[self currentPlaceHolderImage]