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

Commit

Permalink
[WEEX-215][iOS] recycle-list scroll orientation support
Browse files Browse the repository at this point in the history
  • Loading branch information
zerdzhong committed Feb 12, 2018
1 parent 460b427 commit ebd9aa5
Showing 1 changed file with 30 additions and 5 deletions.
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

0 comments on commit ebd9aa5

Please sign in to comment.