From 563f1a7fe1d51cb287bf81d44d1e539bcd1dcce1 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Thu, 16 Sep 2021 19:02:45 +0800 Subject: [PATCH] iOS: fix when reuse flexnode, its childNode cannot measure properly --- doric-iOS/Pod/Classes/Shader/DoricFlexNode.m | 26 +++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/doric-iOS/Pod/Classes/Shader/DoricFlexNode.m b/doric-iOS/Pod/Classes/Shader/DoricFlexNode.m index f92b0673..109ae223 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricFlexNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricFlexNode.m @@ -31,17 +31,16 @@ - (CGSize)sizeThatFits:(CGSize)size { [view.doricLayout measure:size]; [view configureLayoutWithBlock:^(YGLayout *layout) { layout.isEnabled = YES; + if (view.doricLayout.undefined) { + return; + } if (layout.width.unit == YGUnitUndefined || layout.width.unit == YGUnitAuto) { - if (!view.doricLayout.undefined) { - layout.width = YGPointValue(view.doricLayout.measuredWidth); - } + layout.width = YGPointValue(view.doricLayout.measuredWidth); } if (layout.height.unit == YGUnitUndefined || layout.height.unit == YGUnitAuto) { - if (!view.doricLayout.undefined) { - layout.height = YGPointValue(view.doricLayout.measuredHeight); - } + layout.height = YGPointValue(view.doricLayout.measuredHeight); } }]; } @@ -70,11 +69,26 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop } } +- (void)afterBlended:(NSDictionary *)props { + [super afterBlended:props]; + [self.childNodes forEach:^(DoricViewNode *viewNode) { + NSString *viewId = viewNode.viewId; + NSDictionary *model = [self subModelOf:viewId]; + NSDictionary *dictionary = model[@"dictionary"]; + if (!dictionary[@"flexConfig"]) { + viewNode.view.yoga.width = YGValueAuto; + viewNode.view.yoga.height = YGValueAuto; + } + }]; +} + - (void)blendSubNode:(DoricViewNode *)subNode flexConfig:(NSDictionary *)flexConfig { [subNode.view configureLayoutWithBlock:^(YGLayout *_Nonnull layout) { layout.isEnabled = YES; }]; subNode.view.doricLayout.disabled = YES; + subNode.view.yoga.width = YGValueAuto; + subNode.view.yoga.height = YGValueAuto; [self blendYoga:subNode.view.yoga from:flexConfig]; }