diff --git a/renderer/native/ios/renderer/component/footerrefresh/HippyFooterRefresh.m b/renderer/native/ios/renderer/component/footerrefresh/HippyFooterRefresh.m index cb3d0435a13..cb8cf19c589 100644 --- a/renderer/native/ios/renderer/component/footerrefresh/HippyFooterRefresh.m +++ b/renderer/native/ios/renderer/component/footerrefresh/HippyFooterRefresh.m @@ -71,7 +71,7 @@ - (void)setStatus:(HippyRefreshStatus)status { } switch (status) { case HippyRefreshStatusIdle: { - [UIView animateWithDuration:.2f animations:^{ + [UIView animateWithDuration:HIPPY_REFRESH_ANIM_DURATION animations:^{ UIEdgeInsets insets = self.scrollView.contentInset; self.scrollView.contentInset = UIEdgeInsetsMake(insets.top, insets.left, 0, insets.right); } completion:^(BOOL finished) { @@ -84,7 +84,7 @@ - (void)setStatus:(HippyRefreshStatus)status { CGFloat maxOffset = _scrollView.contentSize.height - height + CGRectGetHeight(self.bounds); height = currentOffset - maxOffset + height; } - [UIView animateWithDuration:.2f animations:^{ + [UIView animateWithDuration:HIPPY_REFRESH_ANIM_DURATION animations:^{ UIEdgeInsets insets = self.scrollView.contentInset; self.scrollView.contentInset = UIEdgeInsetsMake(insets.top, insets.left, height, insets.right); } completion:^(BOOL finished) { @@ -106,10 +106,10 @@ - (void)setStatus:(HippyRefreshStatus)status { } - (void)refresh { - [UIView animateWithDuration:.2f animations:^{ + [UIView animateWithDuration:HIPPY_REFRESH_ANIM_DURATION animations:^{ CGPoint bottomOffset = CGPointMake(0, self.scrollView.contentSize.height - self.scrollView.bounds.size.height + self.scrollView.contentInset.bottom); - [self.scrollView setContentOffset:bottomOffset animated:YES]; + self.scrollView.contentOffset = bottomOffset; } completion:^(BOOL finished) { self.status = HippyRefreshStatusStartLoading; }]; diff --git a/renderer/native/ios/renderer/component/headerrefresh/HippyHeaderRefresh.m b/renderer/native/ios/renderer/component/headerrefresh/HippyHeaderRefresh.m index a4a83164700..2f99987d4fb 100644 --- a/renderer/native/ios/renderer/component/headerrefresh/HippyHeaderRefresh.m +++ b/renderer/native/ios/renderer/component/headerrefresh/HippyHeaderRefresh.m @@ -61,6 +61,14 @@ - (void)resetInset } } +- (void)refresh { + [UIView animateWithDuration:HIPPY_REFRESH_ANIM_DURATION animations:^{ + self.scrollView.contentOffset = CGPointMake(0, -self.bounds.size.height); + } completion:^(BOOL finished) { + self.status = HippyRefreshStatusStartLoading; + }]; +} + - (void)scrollViewDidEndDragging { if (_scrollView && -_scrollView.contentOffset.y > CGRectGetHeight(self.bounds)) { self.status = HippyRefreshStatusStartLoading; @@ -73,7 +81,7 @@ - (void)setStatus:(HippyRefreshStatus)status { } switch (status) { case HippyRefreshStatusIdle: { - [UIView animateWithDuration:.2f animations:^{ + [UIView animateWithDuration:HIPPY_REFRESH_ANIM_DURATION animations:^{ UIEdgeInsets insets = self.scrollView.contentInset; self.scrollView.contentInset = UIEdgeInsetsMake(0, insets.left, insets.bottom, insets.right); } completion:^(BOOL finished) { @@ -81,7 +89,7 @@ - (void)setStatus:(HippyRefreshStatus)status { } break; case HippyRefreshStatusStartLoading: { CGFloat height = CGRectGetHeight(self.bounds); - [UIView animateWithDuration:.2f animations:^{ + [UIView animateWithDuration:HIPPY_REFRESH_ANIM_DURATION animations:^{ UIEdgeInsets insets = self.scrollView.contentInset; self.scrollView.contentInset = UIEdgeInsetsMake(height, insets.left, insets.bottom, insets.right); } completion:^(BOOL finished) { diff --git a/renderer/native/ios/renderer/component/refresh/HippyRefresh.h b/renderer/native/ios/renderer/component/refresh/HippyRefresh.h index 5e883901e57..2e68fe2f315 100644 --- a/renderer/native/ios/renderer/component/refresh/HippyRefresh.h +++ b/renderer/native/ios/renderer/component/refresh/HippyRefresh.h @@ -23,6 +23,9 @@ #import #import "NativeRenderTouchesView.h" + +#define HIPPY_REFRESH_ANIM_DURATION 0.2 // Default expand or collapse animation time + typedef NS_ENUM(NSUInteger, HippyRefreshStatus) { HippyRefreshStatusIdle, HippyRefreshStatusPulling, @@ -38,6 +41,7 @@ typedef NS_ENUM(NSUInteger, HippyRefreshStatus) { @end +/// Base class of HeaderRefresh and FooterRefresh @interface HippyRefresh : NativeRenderTouchesView { @protected __weak UIScrollView *_scrollView; diff --git a/renderer/native/ios/renderer/component/refresh/HippyRefresh.m b/renderer/native/ios/renderer/component/refresh/HippyRefresh.m index 716268a7617..02cff2b8009 100644 --- a/renderer/native/ios/renderer/component/refresh/HippyRefresh.m +++ b/renderer/native/ios/renderer/component/refresh/HippyRefresh.m @@ -51,7 +51,7 @@ - (void)setStatus:(HippyRefreshStatus)status { } - (void)refresh { - [UIView animateWithDuration:.2f animations:^{ + [UIView animateWithDuration:HIPPY_REFRESH_ANIM_DURATION animations:^{ self.scrollView.contentOffset = CGPointZero; } completion:^(BOOL finished) { self.status = HippyRefreshStatusStartLoading;