Skip to content

Commit

Permalink
chore(ios): refactor some code in HippyRefresh
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwcg committed Jul 4, 2024
1 parent c96eeaa commit 799f09a
Show file tree
Hide file tree
Showing 4 changed files with 11 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,7 +106,7 @@ - (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.contentOffset = bottomOffset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ - (void)resetInset
}

- (void)refresh {
[UIView animateWithDuration:.2f animations:^{
[UIView animateWithDuration:HIPPY_REFRESH_ANIM_DURATION animations:^{
self.scrollView.contentOffset = CGPointMake(0, -self.bounds.size.height);
} completion:^(BOOL finished) {
self.status = HippyRefreshStatusStartLoading;
Expand All @@ -81,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 799f09a

Please sign in to comment.