[ASScrollDirection] Ensure definitions of "positive" scroll direction in batch context match the layout controller.

This commit is contained in:
Scott Goodson
2016-03-08 00:52:14 -08:00
parent 6b74ad75a1
commit 5c28bb8e21
5 changed files with 38 additions and 26 deletions

View File

@@ -60,11 +60,13 @@ typedef struct ASRangeGeometry ASRangeGeometry;
{
NSArray *layoutAttributes = [_collectionViewLayout layoutAttributesForElementsInRect:rangeBounds];
NSMutableSet *indexPathSet = [NSMutableSet setWithCapacity:layoutAttributes.count];
for (UICollectionViewLayoutAttributes *la in layoutAttributes) {
//ASDisplayNodeAssert(![indexPathSet containsObject:la.indexPath], @"Shouldn't already contain indexPath");
ASDisplayNodeAssert(la.representedElementCategory != UICollectionElementCategoryDecorationView, @"UICollectionView decoration views are not supported by ASCollectionView");
[indexPathSet addObject:la.indexPath];
}
return indexPathSet;
}

View File

@@ -10,6 +10,7 @@
#import "ASAssert.h"
#import "ASDisplayNode.h"
#import "ASIndexPath.h"
#import "CGRect+ASConvenience.h"
#include <map>
#include <vector>
@@ -48,29 +49,33 @@
- (NSSet *)indexPathsForScrolling:(ASScrollDirection)scrollDirection rangeMode:(ASLayoutRangeMode)rangeMode rangeType:(ASLayoutRangeType)rangeType
{
CGFloat viewportScreenMetric;
ASScrollDirection leadingDirection;
CGSize viewportSize = [self viewportSize];
CGFloat viewportDirectionalSize = 0.0;
ASDirectionalScreenfulBuffer directionalBuffer = { 0, 0 };
ASRangeTuningParameters tuningParameters = [self tuningParametersForRangeMode:rangeMode rangeType:rangeType];
if (_layoutDirection == ASFlowLayoutDirectionHorizontal) {
ASDisplayNodeAssert(scrollDirection == ASScrollDirectionNone || scrollDirection == ASScrollDirectionLeft || scrollDirection == ASScrollDirectionRight, @"Invalid scroll direction");
ASDisplayNodeAssert(scrollDirection == ASScrollDirectionNone ||
scrollDirection == ASScrollDirectionLeft ||
scrollDirection == ASScrollDirectionRight, @"Invalid scroll direction");
viewportScreenMetric = viewportSize.width;
leadingDirection = ASScrollDirectionLeft;
viewportDirectionalSize = viewportSize.width;
directionalBuffer = ASDirectionalScreenfulBufferHorizontal(scrollDirection, tuningParameters);
} else {
ASDisplayNodeAssert(scrollDirection == ASScrollDirectionNone || scrollDirection == ASScrollDirectionUp || scrollDirection == ASScrollDirectionDown, @"Invalid scroll direction");
ASDisplayNodeAssert(scrollDirection == ASScrollDirectionNone ||
scrollDirection == ASScrollDirectionUp ||
scrollDirection == ASScrollDirectionDown, @"Invalid scroll direction");
viewportScreenMetric = viewportSize.height;
leadingDirection = ASScrollDirectionUp;
viewportDirectionalSize = viewportSize.height;
directionalBuffer = ASDirectionalScreenfulBufferVertical(scrollDirection, tuningParameters);
}
ASRangeTuningParameters tuningParameters = [self tuningParametersForRangeMode:rangeMode rangeType:rangeType];
CGFloat backScreens = scrollDirection == leadingDirection ? tuningParameters.leadingBufferScreenfuls : tuningParameters.trailingBufferScreenfuls;
CGFloat frontScreens = scrollDirection == leadingDirection ? tuningParameters.trailingBufferScreenfuls : tuningParameters.leadingBufferScreenfuls;
ASIndexPath startPath = [self findIndexPathAtDistance:(-backScreens * viewportScreenMetric) fromIndexPath:_visibleRange.start];
ASIndexPath endPath = [self findIndexPathAtDistance:(frontScreens * viewportScreenMetric) fromIndexPath:_visibleRange.end];
ASIndexPath startPath = [self findIndexPathAtDistance:(-directionalBuffer.negativeDirection * viewportDirectionalSize)
fromIndexPath:_visibleRange.start];
ASIndexPath endPath = [self findIndexPathAtDistance:(directionalBuffer.positiveDirection * viewportDirectionalSize)
fromIndexPath:_visibleRange.end];
ASDisplayNodeAssert(startPath.section <= endPath.section, @"startPath should never begin at a further position than endPath");

View File

@@ -16,6 +16,18 @@ NS_ASSUME_NONNULL_BEGIN
ASDISPLAYNODE_EXTERN_C_BEGIN
struct ASDirectionalScreenfulBuffer {
CGFloat positiveDirection; // Positive relative to iOS Core Animation layer coordinate space.
CGFloat negativeDirection;
};
typedef struct ASDirectionalScreenfulBuffer ASDirectionalScreenfulBuffer;
ASDirectionalScreenfulBuffer ASDirectionalScreenfulBufferHorizontal(ASScrollDirection scrollDirection,
ASRangeTuningParameters rangeTuningParameters);
ASDirectionalScreenfulBuffer ASDirectionalScreenfulBufferVertical(ASScrollDirection scrollDirection,
ASRangeTuningParameters rangeTuningParameters);
CGRect CGRectExpandToRangeWithScrollableDirections(CGRect rect,
ASRangeTuningParameters tuningParameters,
ASScrollDirection scrollableDirections,

View File

@@ -10,12 +10,6 @@
#import "ASScrollDirection.h"
#import "ASLayoutController.h"
struct ASDirectionalScreenfulBuffer {
CGFloat positiveDirection; // Positive relative to iOS Core Animation layer coordinate space.
CGFloat negativeDirection;
};
typedef struct ASDirectionalScreenfulBuffer ASDirectionalScreenfulBuffer;
ASDirectionalScreenfulBuffer ASDirectionalScreenfulBufferHorizontal(ASScrollDirection scrollDirection,
ASRangeTuningParameters rangeTuningParameters)
{

View File

@@ -19,20 +19,19 @@ BOOL ASDisplayShouldFetchBatchForContext(ASBatchContext *context,
return NO;
}
// only Up and Left scrolls are currently supported (tail loading)
if (scrollDirection != ASScrollDirectionUp && scrollDirection != ASScrollDirectionLeft) {
// only Down and Right scrolls are currently supported (tail loading)
if (scrollDirection != ASScrollDirectionDown && scrollDirection != ASScrollDirectionRight) {
return NO;
}
// no fetching for null states
if (leadingScreens <= 0.0 ||
CGRectEqualToRect(bounds, CGRectZero)) {
if (leadingScreens <= 0.0 || CGRectEqualToRect(bounds, CGRectZero)) {
return NO;
}
CGFloat viewLength, offset, contentLength;
if (scrollDirection == ASScrollDirectionUp) {
if (scrollDirection == ASScrollDirectionDown) {
viewLength = bounds.size.height;
offset = targetOffset.y;
contentLength = contentSize.height;