[go: nahoru, domu]

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

Commit

Permalink
[iOS] Fix scroller problems. #1633, #1742, #1979 (#2109)
Browse files Browse the repository at this point in the history
  • Loading branch information
wqyfavor authored and doumafang committed Feb 12, 2019
1 parent 979d562 commit ce9c6ec
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ android/sdk/.externalNativeBuild/ndkBuild/

# release
apache_release_temp

android/commons/bin/
android/playground/app/bin/
18 changes: 17 additions & 1 deletion ios/sdk/WeexSDK/Sources/Component/WXRefreshComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,27 @@ - (void)setDisplay
[_indicator.view setHidden:NO];
}
[_indicator start];
[scrollerProtocol setContentOffset:offset animated:YES];
} else {
offset.y = 0;
[_indicator stop];
[UIView animateWithDuration:0.25 animations:^{
[scrollerProtocol setContentOffset:offset];
}];
}
[scrollerProtocol setContentOffset:offset animated:YES];

/* If we are adding elements while refreshing, like this demo:http://dotwe.org/vue/f541ed72a121db8447a233b777003e8a
the scroller cannot stay at (0, 0) when all animations are finished.
So we use
[scrollerProtocol setContentOffset:offset animated:YES];
when _displayState is TRUE and use
[UIView animateWithDuration:0.25 animations:^{
[scrollerProtocol setContentOffset:offset];
}];
when _displayState is FALSE.
All things go well. Probably setContentOffset: has higher priority than setContentOffset:animated:
*/
}

}
Expand Down
26 changes: 20 additions & 6 deletions ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ @implementation WXScrollerComponent
BOOL _scrollStartEvent;
BOOL _scrollEndEvent;
BOOL _isScrolling;
BOOL _isDragging;
CGFloat _pageSize;
CGFloat _loadMoreOffset;
CGFloat _previousLoadMoreContentHeight;
Expand Down Expand Up @@ -624,6 +625,12 @@ - (CGPoint)contentOffset
return rtv;
}

- (void)setContentOffset:(CGPoint)contentOffset
{
UIScrollView *scrollView = (UIScrollView *)self.view;
[scrollView setContentOffset:contentOffset];
}

- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
{
UIScrollView *scrollView = (UIScrollView *)self.view;
Expand Down Expand Up @@ -692,6 +699,8 @@ - (BOOL)requestGestureShouldStopPropagation:(UIGestureRecognizer *)gestureRecogn

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
_isDragging = YES;

if ([_refreshType isEqualToString:@"refreshForAppear"] && _refreshComponent) {
[_refreshComponent setIndicatorHidden:NO];
}
Expand Down Expand Up @@ -749,12 +758,15 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView
}

CGFloat scaleFactor = self.weexInstance.pixelScaleFactor;
[_refreshComponent pullingdown:@{
REFRESH_DISTANCE_Y: @(fabs((scrollView.contentOffset.y - _lastContentOffset.y)/scaleFactor)),
REFRESH_VIEWHEIGHT: @(_refreshComponent.view.frame.size.height/scaleFactor),
REFRESH_PULLINGDISTANCE: @(scrollView.contentOffset.y/scaleFactor),
@"type":@"pullingdown"
}];
if (_isDragging) {
// only trigger pullingDown event when user is dragging
[_refreshComponent pullingdown:@{
REFRESH_DISTANCE_Y: @(fabs((scrollView.contentOffset.y - _lastContentOffset.y)/scaleFactor)),
REFRESH_VIEWHEIGHT: @(_refreshComponent.view.frame.size.height/scaleFactor),
REFRESH_PULLINGDISTANCE: @(fabs(scrollView.contentOffset.y/scaleFactor)),
@"type":@"pullingdown"
}];
}
_lastContentOffset = scrollView.contentOffset;
// check sticky
[self adjustSticky];
Expand Down Expand Up @@ -949,6 +961,8 @@ - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL
[delegate scrollViewDidEndDragging:scrollView willDecelerate:decelerate];
}
}

_isDragging = NO;
}

- (void)loadMoreIfNeed
Expand Down
1 change: 1 addition & 0 deletions ios/sdk/WeexSDK/Sources/Protocol/WXScrollerProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

- (CGPoint)contentOffset;

- (void)setContentOffset:(CGPoint)contentOffset;
- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;

- (CGSize)contentSize;
Expand Down

0 comments on commit ce9c6ec

Please sign in to comment.