diff --git a/AsyncDisplayKit/ASCollectionView.mm b/AsyncDisplayKit/ASCollectionView.mm index a9c79acf1c..0ccfe7b0aa 100644 --- a/AsyncDisplayKit/ASCollectionView.mm +++ b/AsyncDisplayKit/ASCollectionView.mm @@ -690,6 +690,8 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell"; - (void)scrollViewDidScroll:(UIScrollView *)scrollView { + [_rangeController scrollViewDidScroll:scrollView]; + for (_ASCollectionViewCell *collectionCell in _cellsForVisibilityUpdates) { // Only nodes that respond to the selector are added to _cellsForVisibilityUpdates [[collectionCell node] cellNodeVisibilityEvent:ASCellNodeVisibilityEventVisibleRectChanged diff --git a/AsyncDisplayKit/ASTableView.mm b/AsyncDisplayKit/ASTableView.mm index 695b1e8d7e..efc7083016 100644 --- a/AsyncDisplayKit/ASTableView.mm +++ b/AsyncDisplayKit/ASTableView.mm @@ -602,6 +602,8 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; - (void)scrollViewDidScroll:(UIScrollView *)scrollView { + [_rangeController scrollViewDidScroll:scrollView]; + for (_ASTableViewCell *tableCell in _cellsForVisibilityUpdates) { [[tableCell node] cellNodeVisibilityEvent:ASCellNodeVisibilityEventVisibleRectChanged inScrollView:scrollView diff --git a/AsyncDisplayKit/Details/ASRangeController.h b/AsyncDisplayKit/Details/ASRangeController.h index bba570d0e6..47113d4cdb 100644 --- a/AsyncDisplayKit/Details/ASRangeController.h +++ b/AsyncDisplayKit/Details/ASRangeController.h @@ -45,6 +45,11 @@ NS_ASSUME_NONNULL_BEGIN */ - (void)visibleNodeIndexPathsDidChangeWithScrollDirection:(ASScrollDirection)scrollDirection; +/** + * Notify the range controller that a scroll view did scroll. + */ +- (void)scrollViewDidScroll:(UIScrollView *)scrollView; + /** * Add the sized node for `indexPath` as a subview of `contentView`. * diff --git a/AsyncDisplayKit/Details/ASRangeController.mm b/AsyncDisplayKit/Details/ASRangeController.mm index 22ad82e426..244d18e89e 100644 --- a/AsyncDisplayKit/Details/ASRangeController.mm +++ b/AsyncDisplayKit/Details/ASRangeController.mm @@ -61,11 +61,16 @@ static UIApplicationState __ApplicationState = UIApplicationStateActive; #pragma mark - Core visible node range managment API ++ (BOOL)isFirstRangeUpdateForRangeMode:(ASLayoutRangeMode)rangeMode +{ + return (rangeMode == ASLayoutRangeModeInvalid); +} + + (ASLayoutRangeMode)rangeModeForInterfaceState:(ASInterfaceState)interfaceState currentRangeMode:(ASLayoutRangeMode)currentRangeMode { BOOL isVisible = (ASInterfaceStateIncludesVisible(interfaceState)); - BOOL isFirstRangeUpdate = (currentRangeMode == ASLayoutRangeModeInvalid); + BOOL isFirstRangeUpdate = [self isFirstRangeUpdateForRangeMode:currentRangeMode]; if (!isVisible || isFirstRangeUpdate) { return ASLayoutRangeModeMinimum; } @@ -94,6 +99,15 @@ static UIApplicationState __ApplicationState = UIApplicationStateActive; [self scheduleRangeUpdate]; } +- (void)scrollViewDidScroll:(UIScrollView *)scrollView +{ + // If a scroll happenes the current range mode needs to go to full + BOOL isFirstRangeUpdate = [[self class] isFirstRangeUpdateForRangeMode:_currentRangeMode]; + if (!isFirstRangeUpdate && _currentRangeMode != ASLayoutRangeModeFull) { + [self scheduleRangeUpdate]; + } +} + - (void)updateCurrentRangeWithMode:(ASLayoutRangeMode)rangeMode { if (_currentRangeMode != rangeMode) {