From 89333e22528597c7f49936c872b42902ff999cb4 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Fri, 10 Apr 2020 11:37:48 +0800 Subject: [PATCH] iOS:keep iOS behavior align to android --- doric-iOS/Pod/Classes/Shader/DoricFlexNode.m | 33 +++++++++++++++++--- doric-iOS/Pod/Classes/Shader/DoricLayouts.h | 7 ++++- doric-iOS/Pod/Classes/Shader/DoricLayouts.m | 5 --- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/doric-iOS/Pod/Classes/Shader/DoricFlexNode.m b/doric-iOS/Pod/Classes/Shader/DoricFlexNode.m index 1667ecfd..b1be23ca 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricFlexNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricFlexNode.m @@ -27,14 +27,14 @@ @interface DoricFlexView : UIView @implementation DoricFlexView - (CGSize)sizeThatFits:(CGSize)size { - return [self.yoga calculateLayoutWithSize:size]; + return [self.yoga intrinsicSize]; } @end @implementation DoricFlexNode - (UIView *)build { return [[DoricFlexView new] also:^(DoricFlexView *it) { - [it configureLayoutWithBlock:^(YGLayout * _Nonnull layout) { + [it configureLayoutWithBlock:^(YGLayout *_Nonnull layout) { layout.isEnabled = YES; }]; }]; @@ -49,7 +49,7 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop } - (void)blendSubNode:(DoricViewNode *)subNode flexConfig:(NSDictionary *)flexConfig { - [subNode.view configureLayoutWithBlock:^(YGLayout * _Nonnull layout) { + [subNode.view configureLayoutWithBlock:^(YGLayout *_Nonnull layout) { layout.isEnabled = YES; }]; [self blendYoga:subNode.view.yoga from:flexConfig]; @@ -195,8 +195,33 @@ - (YGValue)translateYGValueFromProperty:(id)prop { - (void)requestLayout { [super requestLayout]; for (UIView *view in self.view.subviews) { + if ([view isKindOfClass:[DoricFlexView class]]) { + continue; + } + [view.doricLayout apply]; + } + if (self.view.doricLayout.widthSpec != DoricLayoutFit) { + self.view.yoga.width = YGPointValue(self.view.width); + } + if (self.view.doricLayout.heightSpec != DoricLayoutFit) { + self.view.yoga.height = YGPointValue(self.view.height); + } + [self.view.yoga applyLayoutPreservingOrigin:YES]; + /// Need layout again. + for (UIView *view in self.view.subviews) { + if ([view isKindOfClass:[DoricFlexView class]]) { + continue; + } + if (view.doricLayout.measuredWidth == view.width && view.doricLayout.measuredHeight == view.height) { + continue; + } + view.doricLayout.widthSpec = DoricLayoutJust; + view.doricLayout.heightSpec = DoricLayoutJust; + view.doricLayout.width = view.width; + view.doricLayout.height = view.height; + view.doricLayout.measuredX = view.left; + view.doricLayout.measuredY = view.top; [view.doricLayout apply]; } - [self.view.yoga applyLayoutPreservingOrigin:NO]; } @end diff --git a/doric-iOS/Pod/Classes/Shader/DoricLayouts.h b/doric-iOS/Pod/Classes/Shader/DoricLayouts.h index 2e2167e1..32ae5241 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricLayouts.h +++ b/doric-iOS/Pod/Classes/Shader/DoricLayouts.h @@ -92,6 +92,11 @@ typedef NS_ENUM(NSInteger, DoricGravity) { @property(nonatomic, assign) BOOL resolved; +@property(nonatomic, assign) CGFloat measuredWidth; +@property(nonatomic, assign) CGFloat measuredHeight; +@property(nonatomic, assign) CGFloat measuredX; +@property(nonatomic, assign) CGFloat measuredY; + - (instancetype)init; - (void)apply; @@ -102,4 +107,4 @@ typedef NS_ENUM(NSInteger, DoricGravity) { @interface UIView (DoricLayout) @property(nonatomic, strong) DoricLayout *doricLayout; -@end \ No newline at end of file +@end diff --git a/doric-iOS/Pod/Classes/Shader/DoricLayouts.m b/doric-iOS/Pod/Classes/Shader/DoricLayouts.m index a1b8f50d..fd55b3aa 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricLayouts.m +++ b/doric-iOS/Pod/Classes/Shader/DoricLayouts.m @@ -48,11 +48,6 @@ - (DoricLayout *)doricLayout { @interface DoricLayout () @property(nonatomic, assign) CGFloat contentWidth; @property(nonatomic, assign) CGFloat contentHeight; -@property(nonatomic, assign) CGFloat measuredWidth; - -@property(nonatomic, assign) CGFloat measuredHeight; -@property(nonatomic, assign) CGFloat measuredX; -@property(nonatomic, assign) CGFloat measuredY; @end @implementation DoricLayout