From e4ddb7e270b064ce95a7ee6b582feea25eedacf8 Mon Sep 17 00:00:00 2001 From: Michael Schneider Date: Sat, 12 Mar 2016 15:44:27 -0800 Subject: [PATCH 1/3] Go into full range mode if a scroll happens --- AsyncDisplayKit/ASCollectionView.mm | 2 ++ AsyncDisplayKit/ASTableView.mm | 2 ++ AsyncDisplayKit/Details/ASRangeController.h | 5 +++++ AsyncDisplayKit/Details/ASRangeController.mm | 16 +++++++++++++++- 4 files changed, 24 insertions(+), 1 deletion(-) 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) { From b4b9f0750cdc7a99e94b5dec73790e8c787ad035 Mon Sep 17 00:00:00 2001 From: Michael Schneider Date: Sat, 12 Mar 2016 16:21:29 -0800 Subject: [PATCH 2/3] Improve going into full range mode on scroll --- AsyncDisplayKit/Details/ASRangeController.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AsyncDisplayKit/Details/ASRangeController.mm b/AsyncDisplayKit/Details/ASRangeController.mm index 244d18e89e..06ca78efbe 100644 --- a/AsyncDisplayKit/Details/ASRangeController.mm +++ b/AsyncDisplayKit/Details/ASRangeController.mm @@ -103,7 +103,8 @@ static UIApplicationState __ApplicationState = UIApplicationStateActive; { // If a scroll happenes the current range mode needs to go to full BOOL isFirstRangeUpdate = [[self class] isFirstRangeUpdateForRangeMode:_currentRangeMode]; - if (!isFirstRangeUpdate && _currentRangeMode != ASLayoutRangeModeFull) { + ASLayoutRangeMode newRangeMode = [[self class] rangeModeForInterfaceState:[self interfaceState] currentRangeMode:_currentRangeMode]; + if (!isFirstRangeUpdate && _currentRangeMode != newRangeMode && _currentRangeMode != ASLayoutRangeModeFull) { [self scheduleRangeUpdate]; } } From 13aa891ecf270b733dfece5916437718f24c388b Mon Sep 17 00:00:00 2001 From: Michael Schneider Date: Sat, 12 Mar 2016 17:45:09 -0800 Subject: [PATCH 3/3] Improve way to go into full mode on scroll --- AsyncDisplayKit/ASCollectionView.mm | 8 +++++++- AsyncDisplayKit/ASTableView.mm | 8 +++++++- AsyncDisplayKit/Details/ASRangeController.h | 5 ----- AsyncDisplayKit/Details/ASRangeController.mm | 10 ---------- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/AsyncDisplayKit/ASCollectionView.mm b/AsyncDisplayKit/ASCollectionView.mm index 0ccfe7b0aa..4e0b3f4884 100644 --- a/AsyncDisplayKit/ASCollectionView.mm +++ b/AsyncDisplayKit/ASCollectionView.mm @@ -15,10 +15,12 @@ #import "ASCollectionViewLayoutController.h" #import "ASCollectionViewFlowLayoutInspector.h" #import "ASCollectionViewLayoutFacilitatorProtocol.h" +#import "ASDisplayNodeExtras.h" #import "ASDisplayNode+FrameworkPrivate.h" #import "ASDisplayNode+Beta.h" #import "ASInternalHelpers.h" #import "UICollectionViewLayout+ASConvenience.h" +#import "ASRangeControllerUpdateRangeProtocol+Beta.h" #import "_ASDisplayLayer.h" static const NSUInteger kASCollectionViewAnimationNone = UITableViewRowAnimationNone; @@ -690,7 +692,11 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell"; - (void)scrollViewDidScroll:(UIScrollView *)scrollView { - [_rangeController scrollViewDidScroll:scrollView]; + // If a scroll happenes the current range mode needs to go to full + ASInterfaceState interfaceState = [self interfaceStateForRangeController:_rangeController]; + if (ASInterfaceStateIncludesVisible(interfaceState)) { + [_rangeController updateCurrentRangeWithMode:ASLayoutRangeModeFull]; + } for (_ASCollectionViewCell *collectionCell in _cellsForVisibilityUpdates) { // Only nodes that respond to the selector are added to _cellsForVisibilityUpdates diff --git a/AsyncDisplayKit/ASTableView.mm b/AsyncDisplayKit/ASTableView.mm index efc7083016..75f0020c62 100644 --- a/AsyncDisplayKit/ASTableView.mm +++ b/AsyncDisplayKit/ASTableView.mm @@ -13,12 +13,14 @@ #import "ASCellNode+Internal.h" #import "ASChangeSetDataController.h" #import "ASDelegateProxy.h" +#import "ASDisplayNodeExtras.h" #import "ASDisplayNode+Beta.h" #import "ASDisplayNode+FrameworkPrivate.h" #import "ASInternalHelpers.h" #import "ASLayout.h" #import "ASLayoutController.h" #import "ASRangeController.h" +#import "ASRangeControllerUpdateRangeProtocol+Beta.h" #import "_ASDisplayLayer.h" #import @@ -602,7 +604,11 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; - (void)scrollViewDidScroll:(UIScrollView *)scrollView { - [_rangeController scrollViewDidScroll:scrollView]; + // If a scroll happenes the current range mode needs to go to full + ASInterfaceState interfaceState = [self interfaceStateForRangeController:_rangeController]; + if (ASInterfaceStateIncludesVisible(interfaceState)) { + [_rangeController updateCurrentRangeWithMode:ASLayoutRangeModeFull]; + } for (_ASTableViewCell *tableCell in _cellsForVisibilityUpdates) { [[tableCell node] cellNodeVisibilityEvent:ASCellNodeVisibilityEventVisibleRectChanged diff --git a/AsyncDisplayKit/Details/ASRangeController.h b/AsyncDisplayKit/Details/ASRangeController.h index 47113d4cdb..bba570d0e6 100644 --- a/AsyncDisplayKit/Details/ASRangeController.h +++ b/AsyncDisplayKit/Details/ASRangeController.h @@ -45,11 +45,6 @@ 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 06ca78efbe..c54004ec42 100644 --- a/AsyncDisplayKit/Details/ASRangeController.mm +++ b/AsyncDisplayKit/Details/ASRangeController.mm @@ -99,16 +99,6 @@ 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]; - ASLayoutRangeMode newRangeMode = [[self class] rangeModeForInterfaceState:[self interfaceState] currentRangeMode:_currentRangeMode]; - if (!isFirstRangeUpdate && _currentRangeMode != newRangeMode && _currentRangeMode != ASLayoutRangeModeFull) { - [self scheduleRangeUpdate]; - } -} - - (void)updateCurrentRangeWithMode:(ASLayoutRangeMode)rangeMode { if (_currentRangeMode != rangeMode) {