Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

[WEEX-215][iOS] recycle-list scroll orientation support #1027

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ @implementation WXRecycleListComponent
NSMutableDictionary *_stickyCache;

NSUInteger _previousLoadMoreCellNumber;
WXScrollDirection _scrollDirection;
}

WX_EXPORT_METHOD(@selector(appendData:))
Expand Down Expand Up @@ -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;
Expand All @@ -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];
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down