[ https://issues.apache.org/jira/browse/WEEX-460?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16696422#comment-16696422 ]
ASF GitHub Bot commented on WEEX-460: ------------------------------------- wqyfavor closed pull request #1266: [WEEX-460][iOS] Fix ImageComponent with placeholder of URL cannot display placeholder if main image cannot be downloaded. URL: https://github.com/apache/incubator-weex/pull/1266 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m index c3dbcc2d7b..7f177f3050 100644 --- a/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m +++ b/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m @@ -381,11 +381,23 @@ - (void)updateImage [[self imageLoader] setImageViewWithURL:(UIImageView*)self.view url:[NSURL URLWithString:newURL] placeholderImage:nil options:userInfo progress:^(NSInteger receivedSize, NSInteger expectedSize) { // progress when loading image } completed:^(UIImage *image, NSError *error, WXImageLoaderCacheType cacheType, NSURL *imageURL) { - __strong typeof(weakSelf) strongSelf = weakSelf; - weakSelf.imageDownloadFinish = YES; + __strong typeof(weakSelf) strongSelf = weakSelf; + if (strongSelf == nil) { + return; + } + + strongSelf.imageDownloadFinish = YES; if (error) { // log error message for error WXLogError(@"Error downloading image: %@, detail:%@", imageURL.absoluteString, [error localizedDescription]); + + // retry set placeholder, maybe placeholer image can be downloaded + if (strongSelf.placeholdSrc) { + NSString *newURL = [strongSelf.placeholdSrc copy]; + WX_REWRITE_URL([strongSelf placeholdSrc], WXResourceTypeImage, strongSelf.weexInstance) + [[strongSelf imageLoader] setImageViewWithURL:(UIImageView*)strongSelf.view url:[NSURL URLWithString:newURL] placeholderImage:nil options:nil progress:nil completed:nil]; + return; + } } UIImageView *imageView = (UIImageView *)strongSelf.view; if (imageView && imageView.image != image) { @@ -404,9 +416,9 @@ - (void)updateImage [strongSelf fireEvent:@"load" params:@{ @"success": error? @false : @true,@"size":sizeDict}]; } //check view/img size - if (!error && image && weakSelf.view) { + if (!error && image && strongSelf.view) { double imageSize = image.size.width * image.scale * image.size.height * image.scale; - double viewSize = weakSelf.view.frame.size.height * weakSelf.view.frame.size.width; + double viewSize = strongSelf.view.frame.size.height * strongSelf.view.frame.size.width; if (imageSize > viewSize) { self.weexInstance.performance.imgWrongSizeNum++; } @@ -415,6 +427,10 @@ - (void)updateImage } else { dispatch_async(WXImageUpdateQueue, ^{ __strong typeof(weakSelf) strongSelf = weakSelf; + if (strongSelf == nil) { + return; + } + [strongSelf cancelImage]; void(^downloadFailed)(NSString *, NSError *) = ^void(NSString *url, NSError *error) { ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > ImageComponent with placeholder of URL cannot display placeholder if main > image cannot be downloaded > ---------------------------------------------------------------------------------------------------- > > Key: WEEX-460 > URL: https://issues.apache.org/jira/browse/WEEX-460 > Project: Weex > Issue Type: Bug > Components: iOS > Affects Versions: 0.12 > Reporter: Wang Qianyuan > Assignee: acton393 > Priority: Major > > <image src="http://www.example.com/test.png" > placeholder="https://cdn.dribbble.com/users/79978/screenshots/3892720/bliss_club.png" > style="width:500px;height:400px"></image> > Placeholder is also indicated by url, if main image cannot be downloaded. On > iOS nothing shows, but on Android and Web the placeholder can be displayed. -- This message was sent by Atlassian JIRA (v7.6.3#76005)