feat:add loadCallback for image network loading callback
This commit is contained in:
@@ -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];
|
||||
}
|
||||
|
Reference in New Issue
Block a user