From 4c80e5aa604e45839409ec6b2e6d97d610901160 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Fri, 12 Nov 2021 16:23:01 +0800 Subject: [PATCH] iOS: fix when Image async load cause super node requestLayout --- .../Pod/Classes/Shader/DoricFlowLayoutNode.m | 5 +++ doric-iOS/Pod/Classes/Shader/DoricImageNode.m | 33 ++++++++++--------- doric-iOS/Pod/Classes/Shader/DoricListNode.m | 4 +++ .../Pod/Classes/Shader/DoricSliderNode.m | 5 +++ doric-iOS/Pod/Classes/Shader/DoricSuperNode.h | 2 ++ doric-iOS/Pod/Classes/Shader/DoricSuperNode.m | 9 +++++ 6 files changed, 42 insertions(+), 16 deletions(-) diff --git a/doric-iOS/Pod/Classes/Shader/DoricFlowLayoutNode.m b/doric-iOS/Pod/Classes/Shader/DoricFlowLayoutNode.m index 24317a24..69941375 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricFlowLayoutNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricFlowLayoutNode.m @@ -540,4 +540,9 @@ - (void)reset { self.onScrollEndFuncId = nil; self.loadMore = NO; } + +- (void)subNodeContentChanged:(DoricViewNode *)subNode { + [subNode.view.doricLayout apply]; + [super subNodeContentChanged:subNode]; +} @end diff --git a/doric-iOS/Pod/Classes/Shader/DoricImageNode.m b/doric-iOS/Pod/Classes/Shader/DoricImageNode.m index 5c8cb87f..7b4c9f3c 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricImageNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricImageNode.m @@ -252,11 +252,9 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id UIImage *image = [UIImage imageWithData:imageData scale:self.imageScale]; #endif view.image = image; - DoricSuperNode *node = self.superNode; - while (node.superNode != nil) { - node = node.superNode; + if (self.needReload) { + [self.superNode subNodeContentChanged:self]; } - [node requestLayout]; if (self.loadCallbackId.length > 0) { if (image) { [self callJSResponse:self.loadCallbackId, @@ -326,12 +324,8 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id }, nil]; } - if (async) { - DoricSuperNode *node = self.superNode; - while (node.superNode != nil) { - node = node.superNode; - } - [node requestLayout]; + if (async && self.needReload) { + [self.superNode subNodeContentChanged:self]; } } }]; @@ -368,12 +362,8 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id }, nil]; } - if (async) { - DoricSuperNode *node = self.superNode; - while (node.superNode != nil) { - node = node.superNode; - } - [node requestLayout]; + if (async && self.needReload) { + [self.superNode subNodeContentChanged:self]; } } }]; @@ -644,4 +634,15 @@ - (void)reset { self.blurEffectView = nil; self.view.contentMode = UIViewContentModeScaleAspectFill; } + +- (BOOL)needReload { + if (self.view.doricLayout.widthSpec == DoricLayoutFit + || self.view.doricLayout.heightSpec == DoricLayoutFit) { + CGSize size = [self.view sizeThatFits:self.view.bounds.size]; + if (!CGSizeEqualToSize(size, self.view.bounds.size)) { + return YES; + } + } + return NO; +} @end diff --git a/doric-iOS/Pod/Classes/Shader/DoricListNode.m b/doric-iOS/Pod/Classes/Shader/DoricListNode.m index 1925abc8..0c31fe3a 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricListNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricListNode.m @@ -488,4 +488,8 @@ - (void)reset { self.loadMore = NO; } +- (void)subNodeContentChanged:(DoricViewNode *)subNode { + [subNode.view.doricLayout apply]; + [super subNodeContentChanged:subNode]; +} @end diff --git a/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m b/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m index 3a315a9a..58f99c1f 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m @@ -314,4 +314,9 @@ - (void)reset { self.propRenderPageFuncId = nil; self.renderPageFuncId = nil; } + +- (void)subNodeContentChanged:(DoricViewNode *)subNode { + [subNode.view.doricLayout apply]; + [super subNodeContentChanged:subNode]; +} @end diff --git a/doric-iOS/Pod/Classes/Shader/DoricSuperNode.h b/doric-iOS/Pod/Classes/Shader/DoricSuperNode.h index ce9640a3..bbd4216f 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricSuperNode.h +++ b/doric-iOS/Pod/Classes/Shader/DoricSuperNode.h @@ -40,4 +40,6 @@ - (void)recursiveMixin:(NSDictionary *)srcModel to:(NSMutableDictionary *)targetModel; - (NSArray *)getSubNodeViewIds; + +- (void)subNodeContentChanged:(DoricViewNode *)subNode; @end diff --git a/doric-iOS/Pod/Classes/Shader/DoricSuperNode.m b/doric-iOS/Pod/Classes/Shader/DoricSuperNode.m index 4b840e0e..caf1ab54 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricSuperNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricSuperNode.m @@ -152,6 +152,15 @@ - (void)reset { for (NSString *viewId in self.subNodes.allKeys) { [[self subNodeWithViewId:viewId] reset]; } +} +- (void)subNodeContentChanged:(DoricViewNode *)subNode { + if (self.superNode + && (self.view.doricLayout.widthSpec == DoricLayoutFit + || self.view.doricLayout.heightSpec == DoricLayoutFit)) { + [self.superNode subNodeContentChanged:self]; + } else { + [self requestLayout]; + } } @end