iOS:add minWidth and minHeight for DoricLayout

This commit is contained in:
pengfei.zhou 2020-04-11 09:38:27 +08:00 committed by osborn
parent c70e1cb20c
commit 4ea7683003
2 changed files with 22 additions and 12 deletions

View File

@ -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;

View File

@ -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.maxHeight > 0) {
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(