Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading