Repository: incubator-weex Updated Branches: refs/heads/master 0e74f4f94 -> 22cbd5b11
[WEEX-220][iOS] recycle-list horizontal layout support loadmore event close #1033 Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/22cbd5b1 Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/22cbd5b1 Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/22cbd5b1 Branch: refs/heads/master Commit: 22cbd5b1114f6960b094da085ea2cd211ca97b47 Parents: 0e74f4f Author: zerdzhong <[email protected]> Authored: Tue Feb 13 17:13:08 2018 +0800 Committer: acton393 <[email protected]> Committed: Mon Feb 26 17:50:46 2018 +0800 ---------------------------------------------------------------------- .../RecycleList/WXRecycleListComponent.m | 12 +++------ .../Sources/Component/WXScrollerComponent.m | 28 +++++++++++++++++--- 2 files changed, 28 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/22cbd5b1/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListComponent.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListComponent.m b/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListComponent.m index b3eb315..a98119f 100644 --- a/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListComponent.m +++ b/ios/sdk/WeexSDK/Sources/Component/RecycleList/WXRecycleListComponent.m @@ -48,7 +48,6 @@ NSMutableDictionary *_stickyCache; NSUInteger _previousLoadMoreCellNumber; - WXScrollDirection _scrollDirection; } WX_EXPORT_METHOD(@selector(appendData:)) @@ -78,7 +77,6 @@ WX_EXPORT_METHOD(@selector(setListData:)) _indexKey = [WXConvert NSString:attributes[@"index"]]; _sizeCache = [NSMutableDictionary dictionary]; _stickyCache = [NSMutableDictionary dictionary]; - _scrollDirection = attributes[@"scrollDirection"] ? [WXConvert WXScrollDirection:attributes[@"scrollDirection"]] : WXScrollDirectionVertical; } return self; @@ -116,6 +114,8 @@ WX_EXPORT_METHOD(@selector(setListData:)) - (void)updateAttributes:(NSDictionary *)attributes { + [super updateAttributes:attributes]; + if (attributes[@"listData"]) { NSArray *listData = attributes[@"listData"]; [self _updateListData:listData withCompletion:nil animation:NO]; @@ -447,11 +447,7 @@ WX_EXPORT_METHOD(@selector(setListData:)) } - (void)_updateScrollDirection:(WXScrollDirection)newScrollDirection -{ - if (_scrollDirection == newScrollDirection) { - return; - } - _scrollDirection = newScrollDirection; +{ WXRecycleListLayout *layout = [self recycleListLayout]; _collectionView.collectionViewLayout = layout; } @@ -463,7 +459,7 @@ WX_EXPORT_METHOD(@selector(setListData:)) // 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) { + if (WXScrollDirectionHorizontal == self.scrollDirection) { layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; } return layout; http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/22cbd5b1/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m ---------------------------------------------------------------------- diff --git a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m index 6f9ae30..5508fba 100644 --- a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m +++ b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.m @@ -269,6 +269,10 @@ WX_EXPORT_METHOD(@selector(resetLoadmore)) if (attributes[@"offsetAccuracy"]) { _offsetAccuracy = [WXConvert WXPixelType:attributes[@"offsetAccuracy"] scaleFactor:self.weexInstance.pixelScaleFactor]; } + + if (attributes[@"scrollDirection"]) { + _scrollDirection = attributes[@"scrollDirection"] ? [WXConvert WXScrollDirection:attributes[@"scrollDirection"]] : WXScrollDirectionVertical; + } } - (void)addEvent:(NSString *)eventName @@ -443,8 +447,14 @@ WX_EXPORT_METHOD(@selector(resetLoadmore)) - (BOOL)isNeedLoadMore { - if (_loadMoreOffset >= 0.0 && ((UIScrollView *)self.view).contentOffset.y >= 0) { - return _previousLoadMoreContentHeight != ((UIScrollView *)self.view).contentSize.height && ((UIScrollView *)self.view).contentSize.height - ((UIScrollView *)self.view).contentOffset.y - self.view.frame.size.height <= _loadMoreOffset; + if (WXScrollDirectionVertical == _scrollDirection) { + if (_loadMoreOffset >= 0.0 && ((UIScrollView *)self.view).contentOffset.y >= 0) { + return _previousLoadMoreContentHeight != ((UIScrollView *)self.view).contentSize.height && ((UIScrollView *)self.view).contentSize.height - ((UIScrollView *)self.view).contentOffset.y - self.view.frame.size.height <= _loadMoreOffset; + } + } else if (WXScrollDirectionHorizontal == _scrollDirection) { + if (_loadMoreOffset >= 0.0 && ((UIScrollView *)self.view).contentOffset.x >= 0) { + return _previousLoadMoreContentHeight != ((UIScrollView *)self.view).contentSize.width && ((UIScrollView *)self.view).contentSize.width - ((UIScrollView *)self.view).contentOffset.x - self.view.frame.size.width <= _loadMoreOffset; + } } return NO; @@ -453,7 +463,12 @@ WX_EXPORT_METHOD(@selector(resetLoadmore)) - (void)loadMore { [self fireEvent:@"loadmore" params:nil]; - _previousLoadMoreContentHeight = ((UIScrollView *)self.view).contentSize.height; + + if (WXScrollDirectionVertical == _scrollDirection) { + _previousLoadMoreContentHeight = ((UIScrollView *)self.view).contentSize.height; + } else if (WXScrollDirectionHorizontal == _scrollDirection) { + _previousLoadMoreContentHeight = ((UIScrollView *)self.view).contentSize.width; + } } - (CGPoint)contentOffset @@ -547,11 +562,16 @@ WX_EXPORT_METHOD(@selector(resetLoadmore)) _direction = @"right"; } else if (_lastContentOffset.x < scrollView.contentOffset.x) { _direction = @"left"; + if (WXScrollDirectionHorizontal == _scrollDirection) { + [self handleLoadMore]; + } } else if(_lastContentOffset.y > scrollView.contentOffset.y) { _direction = @"down"; } else if(_lastContentOffset.y < scrollView.contentOffset.y) { _direction = @"up"; - [self handleLoadMore]; + if (WXScrollDirectionVertical == _scrollDirection) { + [self handleLoadMore]; + } } CGFloat scaleFactor = self.weexInstance.pixelScaleFactor;
