You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ha...@apache.org on 2017/10/10 13:58:16 UTC
[10/15] incubator-weex git commit: * [ios] update image load
performance
* [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/34b7b1b5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/34b7b1b5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/34b7b1b5
Branch: refs/heads/website
Commit: 34b7b1b530bb018e97763a1431622382c1344552
Parents: 93c95f2
Author: acton393 <zh...@gmail.com>
Authored: Mon Oct 9 21:39:16 2017 +0800
Committer: gurisxie <27...@qq.com>
Committed: Tue Oct 10 12:11:25 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/34b7b1b5/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