Update range mode selection logic in ASRangeControllerBeta

This commit is contained in:
Huy Nguyen
2016-02-04 16:51:21 -08:00
parent 79f7450742
commit a7df20d120
2 changed files with 7 additions and 10 deletions

View File

@@ -29,6 +29,8 @@ typedef NS_ENUM(NSUInteger, ASLayoutRangeMode) {
ASLayoutRangeModeCount
};
#define ASLayoutRangeModeInvalid ASLayoutRangeModeCount
typedef NS_ENUM(NSInteger, ASLayoutRangeType) {
ASLayoutRangeTypeDisplay,
ASLayoutRangeTypeFetchData,

View File

@@ -41,7 +41,7 @@
}
_rangeIsValid = YES;
_currentRangeMode = ASLayoutRangeModeCount;
_currentRangeMode = ASLayoutRangeModeInvalid;
return self;
}
@@ -56,19 +56,15 @@
#pragma mark - Core visible node range managment API
+ (ASLayoutRangeMode)rangeModeForInterfaceState:(ASInterfaceState)interfaceState
scrollDirection:(ASScrollDirection)scrollDirection
currentRangeMode:(ASLayoutRangeMode)currentRangeMode
{
BOOL isVisible = (ASInterfaceStateIncludesVisible(interfaceState));
BOOL isScrolling = (scrollDirection != ASScrollDirectionNone);
BOOL isUsingMinimumRangeMode = (currentRangeMode == ASLayoutRangeModeMinimum);
// If we are already visible and scrolling, get busy! Better get started on preloading before the user scrolls more...
// If we are already visible and finished displaying minimum mode, extend to full mode
if (isVisible && (isScrolling || isUsingMinimumRangeMode)) {
return ASLayoutRangeModeFull;
BOOL isFirstRangeUpdate = (currentRangeMode == ASLayoutRangeModeInvalid);
if (!isVisible || isFirstRangeUpdate) {
return ASLayoutRangeModeMinimum;
}
return ASLayoutRangeModeMinimum;
return ASLayoutRangeModeFull;
}
- (void)visibleNodeIndexPathsDidChangeWithScrollDirection:(ASScrollDirection)scrollDirection
@@ -282,7 +278,6 @@
{
if (!_didRegisterForNotifications) {
ASLayoutRangeMode nextRangeMode = [ASRangeControllerBeta rangeModeForInterfaceState:interfaceState
scrollDirection:_scrollDirection
currentRangeMode:_currentRangeMode];
if (_currentRangeMode != nextRangeMode) {
[[NSNotificationCenter defaultCenter] addObserver:self