You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by gu...@apache.org on 2017/10/09 13:57:23 UTC

incubator-weex git commit: * [ios] update image load performance

Repository: incubator-weex
Updated Branches:
  refs/heads/release-0.16 31eb130dc -> e9ea1b279


* [ios] update image load performance


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

Branch: refs/heads/release-0.16
Commit: e9ea1b27953be6b564b69ec825cb601cc634e0c2
Parents: 31eb130
Author: acton393 <zh...@gmail.com>
Authored: Mon Oct 9 21:39:16 2017 +0800
Committer: gurisxie <27...@qq.com>
Committed: Mon Oct 9 21:48:49 2017 +0800

----------------------------------------------------------------------
 .../Sources/Component/WXImageComponent.m        | 89 ++++++++++----------
 1 file changed, 45 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/e9ea1b27/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 90c29a1..4cbe4da 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m
@@ -336,14 +336,17 @@ WX_EXPORT_METHOD(@selector(save:))
 
 - (void)setImageSrc:(NSString*)src
 {
-    pthread_mutex_lock(&(_imageSrcMutex));
-    if (![src isEqualToString:_imageSrc]) {
-        _imageSrc = src;
-        _imageDownloadFinish = NO;
-        ((UIImageView*)self.view).image = nil;
-        [self updateImage];
+    if ([src isEqualToString:_imageSrc]) {
+        // if image src is equal to then ignore it.
+        return;
     }
+    pthread_mutex_lock(&(_imageSrcMutex));
+    _imageSrc = src;
+    _imageDownloadFinish = NO;
+    ((UIImageView*)self.view).image = nil;
     pthread_mutex_unlock(&(_imageSrcMutex));
+    
+    [self updateImage];
 }
 
 - (void)updateImage
@@ -426,45 +429,43 @@ WX_EXPORT_METHOD(@selector(save:))
     NSString * newURL = [imageSrc copy];
     WX_REWRITE_URL(imageSrc, WXResourceTypeImage, self.weexInstance)
     __weak typeof(self) weakSelf = self;
-    dispatch_async(dispatch_get_main_queue(), ^{
-        weakSelf.imageOperation = [[weakSelf imageLoader] downloadImageWithURL:newURL imageFrame:weakSelf.calculatedFrame userInfo:userInfo completed:^(UIImage *image, NSError *error, BOOL finished) {
-            dispatch_async(dispatch_get_main_queue(), ^{
-                __strong typeof(self) strongSelf = weakSelf;
-                
-                if (strongSelf.imageLoadEvent) {
-                    NSMutableDictionary *sizeDict = [NSMutableDictionary new];
-                    sizeDict[@"naturalWidth"] = @0;
-                    sizeDict[@"naturalHeight"] = @0;
-                    if (!error) {
-                        sizeDict[@"naturalWidth"] = @(image.size.width * image.scale);
-                        sizeDict[@"naturalHeight"] = @(image.size.height * image.scale);
-                    } else {
-                        [sizeDict setObject:[error description]?:@"" forKey:@"errorDesc"];
-                    }
-                    [strongSelf fireEvent:@"load" params:@{ @"success": error? @false : @true,@"size":sizeDict}];
-                }
-                if (error) {
-                    downloadFailedBlock(imageSrc, error);
-                    [strongSelf readyToRender];
-                    return ;
-                }
-                
-                if (![imageSrc isEqualToString:strongSelf.imageSrc]) {
-                    return ;
-                }
-                
-                if ([strongSelf isViewLoaded]) {
-                    strongSelf.imageDownloadFinish = YES;
-                    ((UIImageView *)strongSelf.view).image = image;
-                    [strongSelf readyToRender];
-                } else if (strongSelf->_isCompositingChild) {
-                    strongSelf.imageDownloadFinish = YES;
-                    strongSelf->_image = image;
-                    [strongSelf setNeedsDisplay];
+    weakSelf.imageOperation = [[weakSelf imageLoader] downloadImageWithURL:newURL imageFrame:weakSelf.calculatedFrame userInfo:userInfo completed:^(UIImage *image, NSError *error, BOOL finished) {
+        dispatch_async(dispatch_get_main_queue(), ^{
+            __strong typeof(self) strongSelf = weakSelf;
+            
+            if (strongSelf.imageLoadEvent) {
+                NSMutableDictionary *sizeDict = [NSMutableDictionary new];
+                sizeDict[@"naturalWidth"] = @0;
+                sizeDict[@"naturalHeight"] = @0;
+                if (!error) {
+                    sizeDict[@"naturalWidth"] = @(image.size.width * image.scale);
+                    sizeDict[@"naturalHeight"] = @(image.size.height * image.scale);
+                } else {
+                    [sizeDict setObject:[error description]?:@"" forKey:@"errorDesc"];
                 }
-            });
-        }];
-    });
+                [strongSelf fireEvent:@"load" params:@{ @"success": error? @false : @true,@"size":sizeDict}];
+            }
+            if (error) {
+                downloadFailedBlock(imageSrc, error);
+                [strongSelf readyToRender];
+                return ;
+            }
+            
+            if (![imageSrc isEqualToString:strongSelf.imageSrc]) {
+                return ;
+            }
+            
+            if ([strongSelf isViewLoaded]) {
+                strongSelf.imageDownloadFinish = YES;
+                ((UIImageView *)strongSelf.view).image = image;
+                [strongSelf readyToRender];
+            } else if (strongSelf->_isCompositingChild) {
+                strongSelf.imageDownloadFinish = YES;
+                strongSelf->_image = image;
+                [strongSelf setNeedsDisplay];
+            }
+        });
+    }];
 }
 
 - (void)readyToRender