You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ac...@apache.org on 2017/08/10 06:25:08 UTC
incubator-weex git commit: * [ios] ignore image update when src is
empty
Repository: incubator-weex
Updated Branches:
refs/heads/0.16-dev 78e92039b -> 8b9845ebe
* [ios] ignore image update when src is empty
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/8b9845eb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/8b9845eb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/8b9845eb
Branch: refs/heads/0.16-dev
Commit: 8b9845ebe0edabdac0f4eaa4eb4509d6a0071ec6
Parents: 78e9203
Author: acton393 <zh...@gmail.com>
Authored: Thu Aug 10 14:24:42 2017 +0800
Committer: acton393 <zh...@gmail.com>
Committed: Thu Aug 10 14:24:42 2017 +0800
----------------------------------------------------------------------
.../Sources/Component/WXImageComponent.m | 150 ++++++++++---------
1 file changed, 79 insertions(+), 71 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/8b9845eb/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 849620b..7c76d01 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m
@@ -28,6 +28,7 @@
#import "WXRoundedRect.h"
#import "UIBezierPath+Weex.h"
#import "WXSDKEngine.h"
+#import "WXUtility.h"
@interface WXImageView : UIImageView
@@ -342,90 +343,97 @@ WX_EXPORT_METHOD(@selector(save:))
{
NSString *placeholderSrc = self.placeholdSrc;
- if (placeholderSrc) {
- WXLogDebug(@"Updating image, component:%@, placeholder:%@ ", self.ref, placeholderSrc);
- NSString *newURL = [_placeholdSrc copy];
- WX_REWRITE_URL(_placeholdSrc, WXResourceTypeImage, self.weexInstance)
-
- __weak typeof(self) weakSelf = self;
- self.placeholderOperation = [[self imageLoader] downloadImageWithURL:newURL imageFrame:self.calculatedFrame userInfo:nil completed:^(UIImage *image, NSError *error, BOOL finished) {
+ if ([WXUtility isBlankString:placeholderSrc]) {
+ WXLogError(@"image placeholder src is empty");
+ return;
+ }
+
+ WXLogDebug(@"Updating image, component:%@, placeholder:%@ ", self.ref, placeholderSrc);
+ NSString *newURL = [_placeholdSrc copy];
+ WX_REWRITE_URL(_placeholdSrc, WXResourceTypeImage, self.weexInstance)
+
+ __weak typeof(self) weakSelf = self;
+ self.placeholderOperation = [[self imageLoader] downloadImageWithURL:newURL imageFrame:self.calculatedFrame userInfo:nil completed:^(UIImage *image, NSError *error, BOOL finished) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ __strong typeof(self) strongSelf = weakSelf;
+ UIImage *viewImage = ((UIImageView *)strongSelf.view).image;
+ if (error) {
+ downloadFailedBlock(placeholderSrc,error);
+ if ([strongSelf isViewLoaded] && !viewImage) {
+ ((UIImageView *)(strongSelf.view)).image = nil;
+ [strongSelf readyToRender];
+ }
+ return;
+ }
+ if (![placeholderSrc isEqualToString:strongSelf.placeholdSrc]) {
+ return;
+ }
+
+ if ([strongSelf isViewLoaded] && !viewImage) {
+ ((UIImageView *)strongSelf.view).image = image;
+ strongSelf.imageDownloadFinish = YES;
+ [strongSelf readyToRender];
+ } else if (strongSelf->_isCompositingChild) {
+ strongSelf->_image = image;
+ strongSelf.imageDownloadFinish = YES;
+ }
+ });
+ }];
+}
+
+- (void)updateContentImageWithFailedBlock:(void(^)(NSString *, NSError *))downloadFailedBlock
+{
+ NSString *imageSrc = self.imageSrc;
+
+ if ([WXUtility isBlankString:imageSrc]) {
+ WXLogError(@"image src is empty");
+ return;
+ }
+
+ WXLogDebug(@"Updating image:%@, component:%@", self.imageSrc, self.ref);
+ NSDictionary *userInfo = @{@"imageQuality":@(self.imageQuality), @"imageSharp":@(self.imageSharp), @"blurRadius":@(self.blurRadius)};
+ 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;
- UIImage *viewImage = ((UIImageView *)strongSelf.view).image;
- if (error) {
- downloadFailedBlock(placeholderSrc,error);
- if ([strongSelf isViewLoaded] && !viewImage) {
- ((UIImageView *)(strongSelf.view)).image = nil;
- [strongSelf readyToRender];
+
+ 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"];
}
- return;
+ [strongSelf fireEvent:@"load" params:@{ @"success": error? @false : @true,@"size":sizeDict}];
}
- if (![placeholderSrc isEqualToString:strongSelf.placeholdSrc]) {
- return;
+ if (error) {
+ downloadFailedBlock(imageSrc, error);
+ [strongSelf readyToRender];
+ return ;
}
- if ([strongSelf isViewLoaded] && !viewImage) {
- ((UIImageView *)strongSelf.view).image = image;
+ if (![imageSrc isEqualToString:strongSelf.imageSrc]) {
+ return ;
+ }
+
+ if ([strongSelf isViewLoaded]) {
strongSelf.imageDownloadFinish = YES;
+ ((UIImageView *)strongSelf.view).image = image;
[strongSelf readyToRender];
} else if (strongSelf->_isCompositingChild) {
- strongSelf->_image = image;
strongSelf.imageDownloadFinish = YES;
+ strongSelf->_image = image;
+ [strongSelf setNeedsDisplay];
}
});
}];
- }
-}
-
-- (void)updateContentImageWithFailedBlock:(void(^)(NSString *, NSError *))downloadFailedBlock
-{
- NSString *imageSrc = self.imageSrc;
- if (imageSrc) {
- WXLogDebug(@"Updating image:%@, component:%@", self.imageSrc, self.ref);
- NSDictionary *userInfo = @{@"imageQuality":@(self.imageQuality), @"imageSharp":@(self.imageSharp), @"blurRadius":@(self.blurRadius)};
- 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];
- }
- });
- }];
- });
- }
+ });
}
- (void)readyToRender