From f2d2c96619d11d2b29385d5f857239a557bd2cfb Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Tue, 19 Nov 2019 17:49:08 +0800 Subject: [PATCH] feat:List and slider support wrap content in iOS --- iOS/Pod/Classes/Shader/DoricListNode.m | 19 ++++++++++++++++++- iOS/Pod/Classes/Shader/DoricSliderNode.m | 22 +++++++++++++++++++--- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/iOS/Pod/Classes/Shader/DoricListNode.m b/iOS/Pod/Classes/Shader/DoricListNode.m index 4a3c3f90..10792b9b 100644 --- a/iOS/Pod/Classes/Shader/DoricListNode.m +++ b/iOS/Pod/Classes/Shader/DoricListNode.m @@ -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 () @property(nonatomic, strong) NSMutableDictionary *itemViewIds; @property(nonatomic, strong) NSMutableDictionary *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; diff --git a/iOS/Pod/Classes/Shader/DoricSliderNode.m b/iOS/Pod/Classes/Shader/DoricSliderNode.m index 78be0e6f..1ccf6cbc 100644 --- a/iOS/Pod/Classes/Shader/DoricSliderNode.m +++ b/iOS/Pod/Classes/Shader/DoricSliderNode.m @@ -37,6 +37,22 @@ @interface DoricSliderNode () 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 \ No newline at end of file +@end