cxfeng1 closed pull request #1496: [iOS] Add page stop event and custom
pageSize ability to Scroller
URL: https://github.com/apache/incubator-weex/pull/1496
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm
b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm
index bbc780a6f4..1cb3e9aba1 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm
+++ b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm
@@ -77,6 +77,7 @@ @implementation WXScrollerComponent
BOOL _scrollStartEvent;
BOOL _scrollEndEvent;
BOOL _isScrolling;
+ CGFloat _pageSize;
CGFloat _loadMoreOffset;
CGFloat _previousLoadMoreContentHeight;
CGFloat _offsetAccuracy;
@@ -150,6 +151,10 @@ -(instancetype)initWithRef:(NSString *)ref type:(NSString
*)type styles:(NSDicti
_bounces = attributes[@"bounce"]?[WXConvert
BOOL:attributes[@"bounce"]]:YES;
_refreshType = [WXConvert
NSString:attributes[@"refreshType"]]?:@"refreshForWholeVisible";
_pagingEnabled = attributes[@"pagingEnabled"] ? [WXConvert
BOOL:attributes[@"pagingEnabled"]] : NO;
+ _pageSize = attributes[@"pageSize"] ? [WXConvert
WXPixelType:attributes[@"pageSize"]
scaleFactor:self.weexInstance.pixelScaleFactor] : 0;
+ if (_pageSize < 0) {
+ _pageSize = 0;
+ }
_loadMoreOffset = attributes[@"loadmoreoffset"] ? [WXConvert
WXPixelType:attributes[@"loadmoreoffset"]
scaleFactor:self.weexInstance.pixelScaleFactor] : 0;
_loadmoreretry = attributes[@"loadmoreretry"] ? [WXConvert
NSUInteger:attributes[@"loadmoreretry"]] : 0;
_listenLoadMore = [events containsObject:@"loadmore"];
@@ -225,6 +230,14 @@ - (void)viewDidLoad
} else {
scrollView.scrollsToTop = YES;
}
+
+ if (_pagingEnabled && _pageSize > 0) {
+ scrollView.pagingEnabled = NO; // turn off system default paging
+ scrollView.decelerationRate = UIScrollViewDecelerationRateFast;
+ }
+ else {
+ scrollView.decelerationRate = UIScrollViewDecelerationRateNormal;
+ }
}
- (void)layoutDidFinish
@@ -274,9 +287,28 @@ - (void)updateAttributes:(NSDictionary *)attributes
((UIScrollView *)self.view).pagingEnabled = _pagingEnabled;
}
+ if (attributes[@"pageSize"]) {
+ _pageSize = [WXConvert WXPixelType:attributes[@"pageSize"]
+ scaleFactor:self.weexInstance.pixelScaleFactor];
+ if (_pageSize < 0) {
+ _pageSize = 0;
+ }
+ }
+
+ if ([self isViewLoaded]) {
+ if (_pagingEnabled && _pageSize > 0) {
+ ((UIScrollView *)self.view).pagingEnabled = NO; // turn off system
default paging
+ ((UIScrollView *)self.view).decelerationRate =
UIScrollViewDecelerationRateFast;
+ }
+ else {
+ ((UIScrollView *)self.view).decelerationRate =
UIScrollViewDecelerationRateNormal;
+ }
+ }
+
if (attributes[@"loadmoreoffset"]) {
_loadMoreOffset = [WXConvert WXPixelType:attributes[@"loadmoreoffset"]
scaleFactor:self.weexInstance.pixelScaleFactor];
}
+
if (attributes[@"bounce"]) {
_bounces = [WXConvert BOOL:attributes[@"bounce"]];
((UIScrollView *)self.view).bounces = _bounces;
@@ -289,6 +321,7 @@ - (void)updateAttributes:(NSDictionary *)attributes
}
self.loadmoreretry = loadmoreretry;
}
+
if (attributes[@"scrollable"]) {
_scrollable = attributes[@"scrollable"] ? [WXConvert
BOOL:attributes[@"scrollable"]] : YES;
((UIScrollView *)self.view).scrollEnabled = _scrollable;
@@ -758,6 +791,24 @@ - (void)scrollViewDidEndDecelerating:(UIScrollView
*)scrollView
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView
withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint
*)targetContentOffset
{
+ // Page stop effect
+ if (_pagingEnabled && _pageSize > 0) {
+ if (_scrollDirection == WXScrollDirectionVertical) {
+ CGFloat targetY = scrollView.contentOffset.y + velocity.y * 60.0;
+ CGFloat targetIndex = round(targetY / _pageSize);
+ if (targetIndex < 0)
+ targetIndex = 0;
+ targetContentOffset->y = targetIndex * _pageSize;
+ }
+ else {
+ CGFloat targetX = scrollView.contentOffset.x + velocity.x * 60.0;
+ CGFloat targetIndex = round(targetX / _pageSize);
+ if (targetIndex < 0)
+ targetIndex = 0;
+ targetContentOffset->x = targetIndex * _pageSize;
+ }
+ }
+
if ([_refreshType isEqualToString:@"refreshForAppear"]) {
if(targetContentOffset == nil)
return;
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services