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

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