iOS: fix image's stretch mode error when async load image data.

This commit is contained in:
吴尚昆 2022-03-17 17:30:25 +08:00 committed by osborn
parent 3f017a9beb
commit 3d4326ba7b

View File

@ -86,6 +86,8 @@ @interface DoricImageNode ()
@property(nonatomic, strong) NSDictionary *stretchInsetDic; @property(nonatomic, strong) NSDictionary *stretchInsetDic;
@property(nonatomic, strong) NSDictionary *tileInsetDic; @property(nonatomic, strong) NSDictionary *tileInsetDic;
@property(nonatomic, assign) CGFloat imageScale; @property(nonatomic, assign) CGFloat imageScale;
@property(nonatomic, strong) NSDictionary *props;
@end @end
@implementation DoricImageNode @implementation DoricImageNode
@ -123,6 +125,7 @@ - (void)blend:(NSDictionary *)props {
[props[@"loadCallback"] also:^(NSString *it) { [props[@"loadCallback"] also:^(NSString *it) {
self.loadCallbackId = it; self.loadCallbackId = it;
}]; }];
self.props = props;
[super blend:props]; [super blend:props];
} }
@ -281,6 +284,7 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
[self callJSResponse:self.loadCallbackId, nil]; [self callJSResponse:self.loadCallbackId, nil];
} }
} }
[self afterBlended:self.props];
}]; }];
}]; }];
[asyncResult setExceptionCallback:^(NSException *e) { [asyncResult setExceptionCallback:^(NSException *e) {
@ -331,6 +335,7 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
if (async && self.needReload) { if (async && self.needReload) {
[self.superNode subNodeContentChanged:self]; [self.superNode subNodeContentChanged:self];
} }
[self afterBlended:self.props];
} }
}]; }];
}); });
@ -370,6 +375,7 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
[self.superNode subNodeContentChanged:self]; [self.superNode subNodeContentChanged:self];
} }
} }
[self afterBlended:self.props];
}]; }];
#else #else
DoricLog(@"Do not support load image url"); DoricLog(@"Do not support load image url");
@ -663,6 +669,9 @@ - (UIImage *)imageFromData:(NSData *)imgData {
} }
- (void)afterBlended:(NSDictionary *)props { - (void)afterBlended:(NSDictionary *)props {
if (CGSizeEqualToSize(self.view.image.size, CGSizeZero)) {
return;
}
if (self.stretchInsetDic != nil) { if (self.stretchInsetDic != nil) {
CGFloat left = [self.stretchInsetDic[@"left"] floatValue]; CGFloat left = [self.stretchInsetDic[@"left"] floatValue];
CGFloat top = [self.stretchInsetDic[@"top"] floatValue]; CGFloat top = [self.stretchInsetDic[@"top"] floatValue];
@ -682,7 +691,6 @@ - (void)afterBlended:(NSDictionary *)props {
} }
} }
- (NSNumber *)isAnimating { - (NSNumber *)isAnimating {
if (self.view.animating) { if (self.view.animating) {
return @(YES); return @(YES);