feat:optimize refreshable

This commit is contained in:
pengfei.zhou 2019-11-27 19:57:43 +08:00
parent 8b1ed0acc8
commit 459aab61e3
2 changed files with 19 additions and 9 deletions

View File

@ -143,7 +143,7 @@ - (void)setProgressRotation:(CGFloat)rotation {
- (void)setRefreshing:(NSNumber *)refreshable withPromise:(DoricPromise *)promise {
self.view.refreshing = [refreshable boolValue];
[promise resolve:nil];
[promise resolve:nil];
}
- (void)setRefreshable:(NSNumber *)refreshing withPromise:(DoricPromise *)promise {

View File

@ -76,23 +76,24 @@ - (void)setHeaderView:(UIView *)headerView {
self.refreshable = YES;
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (-scrollView.contentOffset.y >= self.headerView.height) {
self.refreshing = YES;
dispatch_async(dispatch_get_main_queue(), ^{
self.refreshing = YES;
});
}
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.contentOffset.y <= 0) {
[self.swipePullingDelegate setProgressRotation:-scrollView.contentOffset.y / self.headerView.height];
//self.bounces = YES;
} else {
//self.bounces = NO;
//scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x, 0);
}
}
- (void)setContentOffset:(CGPoint)contentOffset {
[super setContentOffset:contentOffset];
}
- (void)setRefreshing:(BOOL)refreshing {
if (_refreshing == refreshing) {
return;
@ -101,21 +102,26 @@ - (void)setRefreshing:(BOOL)refreshing {
if (self.onRefreshBlock) {
self.onRefreshBlock();
}
[UIView animateWithDuration:0.3f
[UIView animateWithDuration:.3f
animations:^{
self.contentOffset = (CGPoint) {0, -self.headerView.height};
self.contentInset = UIEdgeInsetsMake(self.headerView.height, 0, 0, 0);
}
completion:^(BOOL finished) {
[self.swipePullingDelegate startAnimation];
self.scrollEnabled = NO;
}
];
} else {
[UIView animateWithDuration:0.3f
self.bounces = YES;
[UIView animateWithDuration:.3f
animations:^{
self.contentOffset = (CGPoint) {0, 0};
self.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
}
completion:^(BOOL finished) {
[self.swipePullingDelegate stopAnimation];
self.scrollEnabled = YES;
}
];
}
@ -124,6 +130,10 @@ - (void)setRefreshing:(BOOL)refreshing {
- (void)setRefreshable:(BOOL)refreshable {
self.scrollEnabled = refreshable;
if (refreshable) {
self.contentOffset = (CGPoint) {0, 0};
self.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
}
}
- (BOOL)refreshable {