feat:Prepare to refact DoricLayouts,because it wont be sized corretly for other views like scrollview or tableview
This commit is contained in:
parent
9be891e284
commit
fe292f7b7f
@ -98,4 +98,6 @@ typedef NS_ENUM(NSInteger, DoricGravity) {
|
||||
- (CGSize)targetLayoutSize;
|
||||
|
||||
- (void)layoutSelf;
|
||||
|
||||
- (CGSize)measureSize:(CGSize)targetSize;
|
||||
@end
|
||||
|
@ -540,17 +540,44 @@ - (CGSize)targetLayoutSize {
|
||||
CGFloat height = self.height;
|
||||
if (self.layoutConfig.widthSpec == DoricLayoutAtMost
|
||||
|| self.layoutConfig.widthSpec == DoricLayoutWrapContent) {
|
||||
width = self.superview.width;
|
||||
width = self.superview.targetLayoutSize.width;
|
||||
}
|
||||
if (self.layoutConfig.heightSpec == DoricLayoutAtMost
|
||||
|| self.layoutConfig.heightSpec == DoricLayoutWrapContent) {
|
||||
height = self.superview.height;
|
||||
height = self.superview.targetLayoutSize.height;
|
||||
}
|
||||
return CGSizeMake(width, height);
|
||||
}
|
||||
|
||||
- (CGSize)measureSize:(CGSize)targetSize {
|
||||
CGFloat width = self.width;
|
||||
CGFloat height = self.height;
|
||||
|
||||
DoricLayoutConfig *config = self.layoutConfig;
|
||||
if (!config) {
|
||||
config = [DoricLayoutConfig new];
|
||||
}
|
||||
if (config.widthSpec == DoricLayoutAtMost
|
||||
|| config.widthSpec == DoricLayoutWrapContent) {
|
||||
width = targetSize.width - config.margin.left - config.margin.right;
|
||||
}
|
||||
if (config.heightSpec == DoricLayoutAtMost
|
||||
|| config.heightSpec == DoricLayoutWrapContent) {
|
||||
height = targetSize.height - config.margin.top - config.margin.bottom;
|
||||
}
|
||||
|
||||
CGSize contentSize = [self sizeThatFits:CGSizeMake(width, height)];
|
||||
if (config.widthSpec == DoricLayoutWrapContent) {
|
||||
width = contentSize.width;
|
||||
}
|
||||
if (config.heightSpec == DoricLayoutWrapContent) {
|
||||
height = contentSize.height;
|
||||
}
|
||||
return CGSizeMake(width, height);
|
||||
}
|
||||
|
||||
- (void)layoutSelf {
|
||||
CGSize contentSize = [self sizeThatFits:self.targetLayoutSize];
|
||||
CGSize contentSize = [self measureSize:self.targetLayoutSize];
|
||||
if (self.layoutConfig.widthSpec == DoricLayoutAtMost) {
|
||||
self.width = self.superview.width;
|
||||
} else if (self.layoutConfig.widthSpec == DoricLayoutWrapContent) {
|
||||
|
@ -21,6 +21,7 @@
|
||||
#import "DoricListNode.h"
|
||||
#import "DoricExtensions.h"
|
||||
#import "DoricListItemNode.h"
|
||||
#import "DoricLayouts.h"
|
||||
|
||||
@interface DoricTableViewCell : UITableViewCell
|
||||
@property(nonatomic, strong) DoricListItemNode *doricListItemNode;
|
||||
@ -39,10 +40,11 @@ - (CGSize)sizeThatFits:(CGSize)size {
|
||||
CGFloat height = 0;
|
||||
|
||||
for (UIView *child in self.subviews) {
|
||||
width = MAX(child.width, width);
|
||||
height += child.height;
|
||||
CGSize childSize = [child measureSize:size];
|
||||
width = MAX(childSize.width, width);
|
||||
height += childSize.height;
|
||||
}
|
||||
return CGSizeMake(width, height);
|
||||
return CGSizeMake(width, MAX(height, size.height));
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
Reference in New Issue
Block a user