Skip to content

Commit

Permalink
修正 MJRefreshAutoStateFooter 在点击 Label 后不刷新的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfcon committed Oct 31, 2019
1 parent 0c1efdd commit 72d558c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
3 changes: 3 additions & 0 deletions MJRefresh/Base/MJRefreshAutoFooter.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ NS_ASSUME_NONNULL_BEGIN

/** 是否每一次拖拽只发一次请求 */
@property (assign, nonatomic, getter=isOnlyRefreshPerDrag) BOOL onlyRefreshPerDrag;

/** 在触发开始刷新前的刷新忽略逻辑, 默认由 isOnlyRefreshPerDrag 和 新手势决定, 用于特殊控制逻辑, 如果不清楚机制, 请勿使用 */
- (BOOL)ignoreRefreshAction NS_REQUIRES_SUPER;
@end

NS_ASSUME_NONNULL_END
44 changes: 31 additions & 13 deletions MJRefresh/Base/MJRefreshAutoFooter.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,46 @@ - (void)scrollViewPanStateDidChange:(NSDictionary *)change
if (self.state != MJRefreshStateIdle) return;

UIGestureRecognizerState panState = _scrollView.panGestureRecognizer.state;
if (panState == UIGestureRecognizerStateEnded) {// 手松开
if (_scrollView.mj_insetT + _scrollView.mj_contentH <= _scrollView.mj_h) { // 不够一个屏幕
if (_scrollView.mj_offsetY >= - _scrollView.mj_insetT) { // 向上拽
[self beginRefreshing];
}
} else { // 超出一个屏幕
if (_scrollView.mj_offsetY >= _scrollView.mj_contentH + _scrollView.mj_insetB - _scrollView.mj_h) {
[self beginRefreshing];

switch (panState) {
// 手松开
case UIGestureRecognizerStateEnded: {
if (_scrollView.mj_insetT + _scrollView.mj_contentH <= _scrollView.mj_h) { // 不够一个屏幕
if (_scrollView.mj_offsetY >= - _scrollView.mj_insetT) { // 向上拽
[self beginRefreshing];
}
} else { // 超出一个屏幕
if (_scrollView.mj_offsetY >= _scrollView.mj_contentH + _scrollView.mj_insetB - _scrollView.mj_h) {
[self beginRefreshing];
}
}
}// ‼️注意: 这里没有 break; fallthrough 执行重置 oneNewPan 语句 (Ended & Canceled & Failed)

case UIGestureRecognizerStateCancelled:
case UIGestureRecognizerStateFailed: {
self.oneNewPan = NO;
}
break;

case UIGestureRecognizerStateBegan: {
self.oneNewPan = YES;
}
} else if (panState == UIGestureRecognizerStateBegan) {
self.oneNewPan = YES;
break;

default:
break;
}
}

- (BOOL)ignoreRefreshAction {
return !self.isOneNewPan && self.isOnlyRefreshPerDrag;
}

- (void)beginRefreshing
{
if (!self.isOneNewPan && self.isOnlyRefreshPerDrag) return;
if ([self ignoreRefreshAction]) return;

[super beginRefreshing];

self.oneNewPan = NO;
}

- (void)setState:(MJRefreshState)state
Expand Down
2 changes: 1 addition & 1 deletion MJRefresh/Base/MJRefreshComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ typedef void (^MJRefreshComponentEndRefreshingCompletionBlock)(void);
- (void)endRefreshingWithCompletionBlock:(void (^)(void))completionBlock;
/** 是否正在刷新 */
@property (assign, nonatomic, readonly, getter=isRefreshing) BOOL refreshing;
//- (BOOL)isRefreshing;

/** 刷新状态 一般交给子类内部实现 */
@property (assign, nonatomic) MJRefreshState state;

Expand Down
10 changes: 9 additions & 1 deletion MJRefresh/Custom/Footer/Auto/MJRefreshAutoStateFooter.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ @interface MJRefreshAutoStateFooter()
}
/** 所有状态对应的文字 */
@property (strong, nonatomic) NSMutableDictionary *stateTitles;
/** 用于判断点击 Label 触发特殊的刷新逻辑 */
@property (assign, nonatomic) BOOL labelIsTrigger;
@end

@implementation MJRefreshAutoStateFooter
Expand Down Expand Up @@ -43,11 +45,17 @@ - (void)setTitle:(NSString *)title forState:(MJRefreshState)state
self.stateLabel.text = self.stateTitles[@(self.state)];
}

- (BOOL)ignoreRefreshAction {
return !self.labelIsTrigger && [super ignoreRefreshAction];
}

#pragma mark - 私有方法
- (void)stateLabelClick
{
if (self.state == MJRefreshStateIdle) {
self.labelIsTrigger = YES;
[self beginRefreshing];
self.labelIsTrigger = NO;
}
}

Expand Down Expand Up @@ -89,4 +97,4 @@ - (void)setState:(MJRefreshState)state
self.stateLabel.text = self.stateTitles[@(state)];
}
}
@end
@end

0 comments on commit 72d558c

Please sign in to comment.