fix(ios): header and footer refresh bugs (#3940)

* fix(ios): header and footer refresh bugs

* chore(ios): refactor some code in HippyRefresh
This commit is contained in:
wwwcg
2024-07-04 11:51:38 +08:00
committed by wwwcg
parent 7a2ce1dc70
commit c151da31be
4 changed files with 19 additions and 7 deletions
@@ -71,7 +71,7 @@
}
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 @@
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)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;
}];
@@ -61,6 +61,14 @@
}
}
- (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 @@
}
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 @@
} 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) {
@@ -23,6 +23,9 @@
#import <UIKit/UIKit.h>
#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;
@@ -51,7 +51,7 @@
}
- (void)refresh {
[UIView animateWithDuration:.2f animations:^{
[UIView animateWithDuration:HIPPY_REFRESH_ANIM_DURATION animations:^{
self.scrollView.contentOffset = CGPointZero;
} completion:^(BOOL finished) {
self.status = HippyRefreshStatusStartLoading;