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/03 07:53:28 UTC
incubator-weex git commit: * [ios] try to fix update image crash
Repository: incubator-weex
Updated Branches:
refs/heads/0.16-dev 6ce0374ff -> 665c5bc54
* [ios] try to fix update image crash
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/665c5bc5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/665c5bc5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/665c5bc5
Branch: refs/heads/0.16-dev
Commit: 665c5bc549d32471a80f9bf16d55f780db707c98
Parents: 6ce0374
Author: acton393 <zh...@gmail.com>
Authored: Thu Aug 3 15:52:58 2017 +0800
Committer: acton393 <zh...@gmail.com>
Committed: Thu Aug 3 15:52:58 2017 +0800
----------------------------------------------------------------------
.../Sources/Component/WXImageComponent.m | 29 ++++++++++++--------
1 file changed, 18 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/665c5bc5/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 1cbf06a..849620b 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXImageComponent.m
@@ -216,6 +216,11 @@ WX_EXPORT_METHOD(@selector(save:))
[self configFilter:styles];
}
+- (void)dealloc
+{
+ [self cancelImage];
+}
+
- (void)updateAttributes:(NSDictionary *)attributes
{
if (attributes[@"src"]) {
@@ -311,21 +316,23 @@ WX_EXPORT_METHOD(@selector(save:))
{
__weak typeof(self) weakSelf = self;
dispatch_async(WXImageUpdateQueue, ^{
- [self cancelImage];
+ __strong typeof(weakSelf) strongSelf = weakSelf;
+ [strongSelf cancelImage];
void(^downloadFailed)(NSString *, NSError *) = ^void(NSString *url, NSError *error) {
weakSelf.imageDownloadFinish = YES;
WXLogError(@"Error downloading image: %@, detail:%@", url, [error localizedDescription]);
};
- [self updatePlaceHolderWithFailedBlock:downloadFailed];
- [self updateContentImageWithFailedBlock:downloadFailed];
+ [strongSelf updatePlaceHolderWithFailedBlock:downloadFailed];
+ [strongSelf updateContentImageWithFailedBlock:downloadFailed];
- if (!weakSelf.imageSrc && !weakSelf.placeholdSrc) {
+ if (!strongSelf.imageSrc && !strongSelf.placeholdSrc) {
dispatch_async(dispatch_get_main_queue(), ^{
- self.layer.contents = nil;
- weakSelf.imageDownloadFinish = YES;
- [weakSelf readyToRender];
+
+ strongSelf.layer.contents = nil;
+ strongSelf.imageDownloadFinish = YES;
+ [strongSelf readyToRender];
});
}
});
@@ -349,7 +356,7 @@ WX_EXPORT_METHOD(@selector(save:))
downloadFailedBlock(placeholderSrc,error);
if ([strongSelf isViewLoaded] && !viewImage) {
((UIImageView *)(strongSelf.view)).image = nil;
- [self readyToRender];
+ [strongSelf readyToRender];
}
return;
}
@@ -359,11 +366,11 @@ WX_EXPORT_METHOD(@selector(save:))
if ([strongSelf isViewLoaded] && !viewImage) {
((UIImageView *)strongSelf.view).image = image;
- weakSelf.imageDownloadFinish = YES;
- [self readyToRender];
+ strongSelf.imageDownloadFinish = YES;
+ [strongSelf readyToRender];
} else if (strongSelf->_isCompositingChild) {
strongSelf->_image = image;
- weakSelf.imageDownloadFinish = YES;
+ strongSelf.imageDownloadFinish = YES;
}
});
}];