From 4ea7683003b8ed7936b54f91f72b99713bbfc9c3 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Sat, 11 Apr 2020 09:38:27 +0800 Subject: [PATCH] iOS:add minWidth and minHeight for DoricLayout --- doric-iOS/Pod/Classes/Shader/DoricLayouts.h | 4 +++ doric-iOS/Pod/Classes/Shader/DoricLayouts.m | 30 ++++++++++++--------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/doric-iOS/Pod/Classes/Shader/DoricLayouts.h b/doric-iOS/Pod/Classes/Shader/DoricLayouts.h index 32ae5241..9aa447d3 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricLayouts.h +++ b/doric-iOS/Pod/Classes/Shader/DoricLayouts.h @@ -90,6 +90,10 @@ typedef NS_ENUM(NSInteger, DoricGravity) { @property(nonatomic, assign) CGFloat maxHeight; +@property(nonatomic, assign) CGFloat minWidth; + +@property(nonatomic, assign) CGFloat minHeight; + @property(nonatomic, assign) BOOL resolved; @property(nonatomic, assign) CGFloat measuredWidth; diff --git a/doric-iOS/Pod/Classes/Shader/DoricLayouts.m b/doric-iOS/Pod/Classes/Shader/DoricLayouts.m index 14e11603..070af531 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricLayouts.m +++ b/doric-iOS/Pod/Classes/Shader/DoricLayouts.m @@ -55,8 +55,10 @@ - (instancetype)init { if (self = [super init]) { _widthSpec = DoricLayoutJust; _heightSpec = DoricLayoutJust; - _maxWidth = -1; - _maxHeight = -1; + _maxWidth = CGFLOAT_MAX; + _maxHeight = CGFLOAT_MAX; + _minWidth = CGFLOAT_MIN; + _minHeight = CGFLOAT_MIN; } return self; } @@ -103,17 +105,21 @@ - (void)measure:(CGSize)targetSize { height - self.paddingTop - self.paddingBottom)]; BOOL needRemeasure = NO; - if (self.maxWidth >= 0) { - if (self.measuredWidth > self.maxWidth) { - self.measuredWidth = self.maxWidth; - needRemeasure = YES; - } + if (self.measuredWidth > self.maxWidth) { + self.measuredWidth = self.maxWidth; + needRemeasure = YES; } - if (self.maxHeight > 0) { - if (self.measuredHeight > self.maxHeight) { - self.measuredHeight = self.maxHeight; - needRemeasure = YES; - } + if (self.measuredHeight > self.maxHeight) { + self.measuredHeight = self.maxHeight; + needRemeasure = YES; + } + if (self.measuredWidth < self.minWidth) { + self.measuredWidth = self.minWidth; + needRemeasure = YES; + } + if (self.measuredHeight < self.minHeight) { + self.measuredHeight = self.minHeight; + needRemeasure = YES; } if (needRemeasure) { [self measureContent:CGSizeMake(