Permalink
Browse files

Don't trigger when scrolling up too fast, should fix #33

  • Loading branch information...
1 parent 79bfad3 commit d39d6d7bf49512d1ae829d0f77f4cfdb67d213f2 @Sephiroth87 committed Oct 8, 2012
Showing with 22 additions and 3 deletions.
  1. +1 −0 ODRefreshControl/ODRefreshControl.h
  2. +21 −3 ODRefreshControl/ODRefreshControl.m
@@ -22,6 +22,7 @@
BOOL _ignoreOffset;
BOOL _didSetInset;
BOOL _hasSectionHeaders;
+ CGFloat _lastOffset;
}
@property (nonatomic, readonly) BOOL refreshing;
@@ -226,21 +226,39 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
}
return;
} else {
- // Check if we can trigger a new refresh
+ // Check if we can trigger a new refresh and if we can draw the control
+ BOOL dontDraw = NO;
if (!_canRefresh) {
if (offset >= 0) {
+ // We can refresh again after the control is scrolled out of view
_canRefresh = YES;
_didSetInset = NO;
} else {
- return;
+ dontDraw = YES;
}
} else {
if (offset >= 0) {
- return;
+ // Don't draw if the control is not visible
+ dontDraw = YES;
}
}
+ if (_lastOffset > offset && !self.scrollView.isTracking) {
+ // If we are scrolling too fast, don't draw, and don't trigger unless the scrollView bounced back
+ _canRefresh = NO;
+ dontDraw = YES;
+ }
+ if (dontDraw) {
+ _shapeLayer.path = nil;
+ _shapeLayer.shadowPath = nil;
+ _arrowLayer.path = nil;
+ _highlightLayer.path = nil;
+ _lastOffset = offset;
+ return;
+ }
}
+ _lastOffset = offset;
+
BOOL triggered = NO;
CGMutablePathRef path = CGPathCreateMutable();

4 comments on commit d39d6d7

Hi,

I think the previous behavior was the right one, I had to undo those changes because I was experiencing strange issues with the reload icon not showing if I was not scrolling slowly from the top of my scrollview.

Except that, it works great, Thanks!

Owner

Sephiroth87 replied Oct 12, 2012

Well, the correct behaviour is this one (especially on iPad it was really easy to trigger the refresh by just scrolling up), but it's totally possible there's a bug somewhere...

I'll check it again...

Could you explain the logic so I can implement this for TwUI?

Owner

Sephiroth87 replied Oct 17, 2012

Well, the part for that is simply that if the current offset is less than the last one (so we are scrolling up), but the scrollView is not tracking (the user is scrolling, the dragging property is different), we don't draw the control...

The part that was already there is for when the user keep pulling the control even after it's finished reloaded.
We don't draw it again until the scrollView gets released or scrolls down.

Please sign in to comment.