feat:List and slider support wrap content in iOS

This commit is contained in:
pengfei.zhou 2019-11-19 17:49:08 +08:00
parent 06f2a0b106
commit f2d2c96619
2 changed files with 37 additions and 4 deletions

View File

@ -29,6 +29,23 @@ @interface DoricTableViewCell : UITableViewCell
@implementation DoricTableViewCell
@end
@interface DoricTableView : UITableView
@end
@implementation DoricTableView
- (CGSize)sizeThatFits:(CGSize)size {
if (self.subviews.count > 0) {
CGFloat width = size.width;
for (UIView *child in self.subviews) {
width = MAX(child.width, width);
}
return CGSizeMake(width, size.width);
}
return size;
}
@end
@interface DoricListNode () <UITableViewDataSource, UITableViewDelegate>
@property(nonatomic, strong) NSMutableDictionary <NSNumber *, NSString *> *itemViewIds;
@property(nonatomic, strong) NSMutableDictionary <NSNumber *, NSNumber *> *itemHeights;
@ -47,7 +64,7 @@ - (instancetype)initWithContext:(DoricContext *)doricContext {
}
- (UITableView *)build {
return [[UITableView new] also:^(UITableView *it) {
return [[DoricTableView new] also:^(UITableView *it) {
it.dataSource = self;
it.delegate = self;
it.separatorStyle = UITableViewCellSeparatorStyleNone;

View File

@ -37,6 +37,22 @@ @interface DoricSliderNode () <UICollectionViewDataSource, UICollectionViewDeleg
@property(nonatomic, assign) NSUInteger batchCount;
@end
@interface DoricCollectionView : UICollectionView
@end
@implementation DoricCollectionView
- (CGSize)sizeThatFits:(CGSize)size {
if (self.subviews.count > 0) {
CGFloat height = size.height;
for (UIView *child in self.subviews) {
height = MAX(child.height, height);
}
return CGSizeMake(height, size.height);
}
return size;
}
@end
@implementation DoricSliderNode
- (instancetype)initWithContext:(DoricContext *)doricContext {
if (self = [super initWithContext:doricContext]) {
@ -50,8 +66,8 @@ - (UICollectionView *)build {
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
return [[[UICollectionView alloc] initWithFrame:CGRectZero
collectionViewLayout:flowLayout]
return [[[DoricCollectionView alloc] initWithFrame:CGRectZero
collectionViewLayout:flowLayout]
also:^(UICollectionView *it) {
it.backgroundColor = [UIColor whiteColor];
it.delegate = self;
@ -165,4 +181,4 @@ - (void)blendSubNode:(NSDictionary *)subModel {
}];
}
}
@end
@end