You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by cx...@apache.org on 2018/06/19 09:41:23 UTC

[36/50] [abbrv] incubator-weex git commit: [WEEX-460][iOS] Fix ImageComponent with placeholder of URL cannot display placeholder if main image cannot be downloaded.

[WEEX-460][iOS] Fix ImageComponent with placeholder of URL cannot display placeholder if main image cannot be downloaded.


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/91d71348
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/91d71348
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/91d71348

Branch: refs/heads/release
Commit: 91d713481c64a9cb0eb2eae4e557495ae61d8660
Parents: 0935d64
Author: 神漠 <qi...@alipay.com>
Authored: Wed Jun 13 21:10:49 2018 +0800
Committer: Adam Feng <cx...@gmail.com>
Committed: Thu Jun 14 14:54:15 2018 +0800

----------------------------------------------------------------------
 .../Sources/Component/WXImageComponent.m        | 24 ++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/91d71348/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m
index c3dbcc2..8ab354b 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m
@@ -382,10 +382,22 @@ WX_EXPORT_METHOD(@selector(save:))
             // progress when loading image
         } completed:^(UIImage *image, NSError *error, WXImageLoaderCacheType cacheType, NSURL *imageURL) {
             __strong typeof(weakSelf) strongSelf =  weakSelf;
-            weakSelf.imageDownloadFinish = YES;
+            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 @@ WX_EXPORT_METHOD(@selector(save:))
                 [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,10 +427,14 @@ WX_EXPORT_METHOD(@selector(save:))
     } else {
         dispatch_async(WXImageUpdateQueue, ^{
              __strong typeof(weakSelf) strongSelf = weakSelf;
+            if (strongSelf == nil) {
+                return;
+            }
+            
             [strongSelf cancelImage];
 
             void(^downloadFailed)(NSString *, NSError *) = ^void(NSString *url, NSError *error) {
-                weakSelf.imageDownloadFinish = YES;
+                strongSelf.imageDownloadFinish = YES;
                 WXLogError(@"Error downloading image: %@, detail:%@", url, [error localizedDescription]);
             };