From ebd9aa5e55cf73f3ae8fa06f64bd21a3727a0641 Mon Sep 17 00:00:00 2001 From: zerdzhong Date: Mon, 12 Feb 2018 10:21:18 +0800 Subject: [PATCH] [WEEX-215][iOS] recycle-list scroll orientation support --- .../RecycleList/WXRecycleListComponent.m | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListComponent.m b/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListComponent.m index 03f233a8e4..b22fe26340 100644 --- a/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListComponent.m +++ b/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListComponent.m @@ -48,6 +48,7 @@ @implementation WXRecycleListComponent NSMutableDictionary *_stickyCache; NSUInteger _previousLoadMoreCellNumber; + WXScrollDirection _scrollDirection; } WX_EXPORT_METHOD(@selector(appendData:)) @@ -77,6 +78,7 @@ - (instancetype)initWithRef:(NSString *)ref _indexKey = [WXConvert NSString:attributes[@"index"]]; _sizeCache = [NSMutableDictionary dictionary]; _stickyCache = [NSMutableDictionary dictionary]; + _scrollDirection = attributes[@"scrollDirection"] ? [WXConvert WXScrollDirection:attributes[@"scrollDirection"]] : WXScrollDirectionVertical; } return self; @@ -86,11 +88,7 @@ - (instancetype)initWithRef:(NSString *)ref - (UIView *)loadView { - WXRecycleListLayout *layout = [WXRecycleListLayout new]; - layout.delegate = self; - // to show cells that original width / height is zero, otherwise cellForItemAtIndexPath will not be called - layout.minimumLineSpacing = 0.01; - layout.minimumInteritemSpacing = 0.01; + WXRecycleListLayout *layout = [self recycleListLayout]; return [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; } @@ -131,6 +129,10 @@ - (void)updateAttributes:(NSDictionary *)attributes if (attributes[@"index"]) { _indexKey = [WXConvert NSString:attributes[@"index"]]; } + if (attributes[@"scrollDirection"]) { + WXScrollDirection newScrollDirection = attributes[@"scrollDirection"] ? [WXConvert WXScrollDirection:attributes[@"scrollDirection"]] : WXScrollDirectionVertical; + [self _updateScrollDirection:newScrollDirection]; + } } - (CGPoint)absolutePositionForComponent:(WXComponent *)component @@ -444,6 +446,29 @@ - (void)_updateListData:(NSArray *)newData [_updateManager updateWithNewData:newData oldData:oldData completion:completion animation:animation]; } +- (void)_updateScrollDirection:(WXScrollDirection)newScrollDirection +{ + if (_scrollDirection == newScrollDirection) { + return; + } + _scrollDirection = newScrollDirection; + WXRecycleListLayout *layout = [self recycleListLayout]; + _collectionView.collectionViewLayout = layout; +} + +- (WXRecycleListLayout *)recycleListLayout +{ + WXRecycleListLayout *layout = [WXRecycleListLayout new]; + layout.delegate = self; + // to show cells that original width / height is zero, otherwise cellForItemAtIndexPath will not be called + layout.minimumLineSpacing = 0.01; + layout.minimumInteritemSpacing = 0.01; + if (_scrollDirection == WXScrollDirectionHorizontal) { + layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; + } + return layout; +} + #pragma mark - UICollectionViewDataSource - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView