Skip to content

Commit

Permalink
Handle edge case with content size not being updated in time in table…
Browse files Browse the repository at this point in the history
… views

See: #31
  • Loading branch information
Andrej Mihajlov committed Apr 20, 2016
1 parent 13ae980 commit 4e6cea3
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Classes/UIScrollView+InfiniteScroll.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ static void PBSwizzleMethod(Class c, SEL original, SEL alternate) {
}
}

/**
* A helper function to force table view to update its content size
*
* See https://github.com/pronebird/UIScrollView-InfiniteScroll/issues/31
*
* @param tableView
*/
static void PBForceUpdateTableViewContentSize(UITableView *tableView) {
tableView.contentSize = [tableView sizeThatFits:CGSizeMake(tableView.frame.size.width, CGFLOAT_MAX)];
}

// Animation duration used for setContentOffset:
static const NSTimeInterval kPBInfiniteScrollAnimationDuration = 0.35;

Expand Down Expand Up @@ -427,6 +438,14 @@ - (void)pb_stopAnimatingInfiniteScrollWithCompletion:(nullable void(^)(id scroll
// Reset extra bottom inset
state.extraBottomInset = 0;

// Force the table view to update its contentSize; if we don't do this,
// finishInfiniteScroll() will adjust contentInsets and cause contentOffset
// to be off by an amount equal to the height of the activity indicator.
// See https://github.com/pronebird/UIScrollView-InfiniteScroll/issues/31
if([self isKindOfClass:[UITableView class]]) {
PBForceUpdateTableViewContentSize((UITableView *)self);
}

// Animate content insets
[self pb_setScrollViewContentInset:contentInset animated:YES completion:^(BOOL finished) {
// Curtain is closing they're throwing roses at my feet
Expand Down Expand Up @@ -458,6 +477,11 @@ - (void)pb_stopAnimatingInfiniteScrollWithCompletion:(nullable void(^)(id scroll
TRACE(@"Stop animating.");
}

/**
* Called whenever content offset changes.
*
* @param contentOffset
*/
- (void)pb_scrollViewDidScroll:(CGPoint)contentOffset {
_PBInfiniteScrollState *state = self.pb_infiniteScrollState;

Expand Down

0 comments on commit 4e6cea3

Please sign in to comment.