From 3d4326ba7b4492adfaf2aaa45c398e18e61fef09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=B0=9A=E6=98=86?= Date: Thu, 17 Mar 2022 17:30:25 +0800 Subject: [PATCH] iOS: fix image's stretch mode error when async load image data. --- doric-iOS/Pod/Classes/Shader/DoricImageNode.m | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/doric-iOS/Pod/Classes/Shader/DoricImageNode.m b/doric-iOS/Pod/Classes/Shader/DoricImageNode.m index 0482769f..f817cf2d 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricImageNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricImageNode.m @@ -86,6 +86,8 @@ @interface DoricImageNode () @property(nonatomic, strong) NSDictionary *stretchInsetDic; @property(nonatomic, strong) NSDictionary *tileInsetDic; @property(nonatomic, assign) CGFloat imageScale; +@property(nonatomic, strong) NSDictionary *props; + @end @implementation DoricImageNode @@ -123,6 +125,7 @@ - (void)blend:(NSDictionary *)props { [props[@"loadCallback"] also:^(NSString *it) { self.loadCallbackId = it; }]; + self.props = props; [super blend:props]; } @@ -281,6 +284,7 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id [self callJSResponse:self.loadCallbackId, nil]; } } + [self afterBlended:self.props]; }]; }]; [asyncResult setExceptionCallback:^(NSException *e) { @@ -331,6 +335,7 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id if (async && self.needReload) { [self.superNode subNodeContentChanged:self]; } + [self afterBlended:self.props]; } }]; }); @@ -370,7 +375,8 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id [self.superNode subNodeContentChanged:self]; } } - }]; + [self afterBlended:self.props]; + }]; #else DoricLog(@"Do not support load image url"); #endif @@ -663,6 +669,9 @@ - (UIImage *)imageFromData:(NSData *)imgData { } - (void)afterBlended:(NSDictionary *)props { + if (CGSizeEqualToSize(self.view.image.size, CGSizeZero)) { + return; + } if (self.stretchInsetDic != nil) { CGFloat left = [self.stretchInsetDic[@"left"] floatValue]; CGFloat top = [self.stretchInsetDic[@"top"] floatValue]; @@ -682,7 +691,6 @@ - (void)afterBlended:(NSDictionary *)props { } } - - (NSNumber *)isAnimating { if (self.view.animating) { return @(YES);