feat:add loadCallback for image network loading callback

This commit is contained in:
pengfei.zhou
2019-11-20 16:03:07 +08:00
parent 5eddc44eb1
commit 38823700a2
5 changed files with 76 additions and 29 deletions

View File

@@ -24,6 +24,10 @@
#import "Doric.h"
#import <SDWebImage/SDWebImage.h>
@interface DoricImageNode ()
@property(nonatomic, copy) NSString *loadCallbackId;
@end
@implementation DoricImageNode
- (UIImageView *)build {
@@ -37,7 +41,19 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
__weak typeof(self) _self = self;
[view sd_setImageWithURL:[NSURL URLWithString:prop] completed:^(UIImage *_Nullable image, NSError *_Nullable error, SDImageCacheType cacheType, NSURL *_Nullable imageURL) {
__strong typeof(_self) self = _self;
[self requestLayout];
if (error) {
if (self.loadCallbackId.length > 0) {
[self callJSResponse:self.loadCallbackId, nil];
}
} else {
if (self.loadCallbackId.length > 0) {
[self callJSResponse:self.loadCallbackId,
@{@"width": @(image.size.width), @"height": @(image.size.height)},
nil];
}
[self requestLayout];
}
}];
} else if ([@"scaleType" isEqualToString:name]) {
switch ([prop integerValue]) {
@@ -54,6 +70,8 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
break;
}
}
} else if ([@"loadCallback" isEqualToString:name]) {
self.loadCallbackId = prop;
} else {
[super blendView:view forPropName:name propValue:prop];
}