Skip to content

Commit

Permalink
fix(ios): header and footer refresh bugs (#3940)
Browse files Browse the repository at this point in the history
* fix(ios): header and footer refresh bugs

* chore(ios): refactor some code in HippyRefresh
  • Loading branch information
wwwcg authored Jul 4, 2024
1 parent b1f1528 commit 3d97378
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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;
}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -73,15 +81,15 @@ - (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) {
}];
} 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) {
Expand Down
4 changes: 4 additions & 0 deletions renderer/native/ios/renderer/component/refresh/HippyRefresh.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -38,6 +41,7 @@ typedef NS_ENUM(NSUInteger, HippyRefreshStatus) {

@end

/// Base class of HeaderRefresh and FooterRefresh
@interface HippyRefresh : NativeRenderTouchesView {
@protected
__weak UIScrollView *_scrollView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3d97378

Please sign in to comment.