diff --git a/AsyncDisplayKit.xcodeproj/project.pbxproj b/AsyncDisplayKit.xcodeproj/project.pbxproj index c32af2805c..ca4d3c60ee 100644 --- a/AsyncDisplayKit.xcodeproj/project.pbxproj +++ b/AsyncDisplayKit.xcodeproj/project.pbxproj @@ -145,6 +145,8 @@ 205F0E0F1B371875007741D0 /* UICollectionViewLayout+ASConvenience.h in Headers */ = {isa = PBXBuildFile; fileRef = 205F0E0D1B371875007741D0 /* UICollectionViewLayout+ASConvenience.h */; settings = {ATTRIBUTES = (Public, ); }; }; 205F0E101B371875007741D0 /* UICollectionViewLayout+ASConvenience.m in Sources */ = {isa = PBXBuildFile; fileRef = 205F0E0E1B371875007741D0 /* UICollectionViewLayout+ASConvenience.m */; }; 205F0E121B371BD7007741D0 /* ASScrollDirection.m in Sources */ = {isa = PBXBuildFile; fileRef = 205F0E111B371BD7007741D0 /* ASScrollDirection.m */; }; + 205F0E191B37339C007741D0 /* ASAbstractLayoutController.h in Headers */ = {isa = PBXBuildFile; fileRef = 205F0E171B37339C007741D0 /* ASAbstractLayoutController.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 205F0E1A1B37339C007741D0 /* ASAbstractLayoutController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 205F0E181B37339C007741D0 /* ASAbstractLayoutController.mm */; }; 242995D31B29743C00090100 /* ASBasicImageDownloaderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 242995D21B29743C00090100 /* ASBasicImageDownloaderTests.m */; }; 2911485C1A77147A005D0878 /* ASControlNodeTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2911485B1A77147A005D0878 /* ASControlNodeTests.m */; }; 291B63FB1AA53A7A000A71B3 /* ASScrollDirection.h in Headers */ = {isa = PBXBuildFile; fileRef = 296A0A311A951715005ACEAA /* ASScrollDirection.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -325,6 +327,8 @@ 205F0E0D1B371875007741D0 /* UICollectionViewLayout+ASConvenience.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UICollectionViewLayout+ASConvenience.h"; sourceTree = ""; }; 205F0E0E1B371875007741D0 /* UICollectionViewLayout+ASConvenience.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UICollectionViewLayout+ASConvenience.m"; sourceTree = ""; }; 205F0E111B371BD7007741D0 /* ASScrollDirection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASScrollDirection.m; sourceTree = ""; }; + 205F0E171B37339C007741D0 /* ASAbstractLayoutController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASAbstractLayoutController.h; sourceTree = ""; }; + 205F0E181B37339C007741D0 /* ASAbstractLayoutController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASAbstractLayoutController.mm; sourceTree = ""; }; 242995D21B29743C00090100 /* ASBasicImageDownloaderTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASBasicImageDownloaderTests.m; sourceTree = ""; }; 2911485B1A77147A005D0878 /* ASControlNodeTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASControlNodeTests.m; sourceTree = ""; }; 292C59991A956527007E5DD6 /* ASLayoutRangeType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASLayoutRangeType.h; sourceTree = ""; }; @@ -544,6 +548,8 @@ 058D09E3195D050800B7D73C /* _ASDisplayLayer.mm */, 058D09E4195D050800B7D73C /* _ASDisplayView.h */, 058D09E5195D050800B7D73C /* _ASDisplayView.mm */, + 205F0E171B37339C007741D0 /* ASAbstractLayoutController.h */, + 205F0E181B37339C007741D0 /* ASAbstractLayoutController.mm */, 054963471A1EA066000F8E56 /* ASBasicImageDownloader.h */, 054963481A1EA066000F8E56 /* ASBasicImageDownloader.mm */, 299DA1A71A828D2900162D41 /* ASBatchContext.h */, @@ -698,6 +704,7 @@ 058D0A5A195D05DC00B7D73C /* ASMutableAttributedStringBuilder.m in Headers */, 058D0A5B195D05DC00B7D73C /* ASTextNodeCoreTextAdditions.h in Headers */, 058D0A5C195D05DC00B7D73C /* ASTextNodeCoreTextAdditions.m in Headers */, + 205F0E191B37339C007741D0 /* ASAbstractLayoutController.h in Headers */, 058D0A5D195D05DC00B7D73C /* ASTextNodeRenderer.h in Headers */, 058D0A5E195D05DC00B7D73C /* ASTextNodeRenderer.mm in Headers */, 058D0A5F195D05DC00B7D73C /* ASTextNodeShadower.h in Headers */, @@ -925,6 +932,7 @@ 058D0A1E195D050800B7D73C /* ASTextNodeShadower.m in Sources */, 058D0A18195D050800B7D73C /* _ASDisplayLayer.mm in Sources */, 058D0A2C195D050800B7D73C /* ASSentinel.m in Sources */, + 205F0E1A1B37339C007741D0 /* ASAbstractLayoutController.mm in Sources */, 464052211A3F83C40061C0BA /* ASDataController.mm in Sources */, 299DA1AA1A828D2900162D41 /* ASBatchContext.mm in Sources */, 058D0A15195D050800B7D73C /* ASDisplayNodeExtras.mm in Sources */, diff --git a/AsyncDisplayKit/Details/ASAbstractLayoutController.h b/AsyncDisplayKit/Details/ASAbstractLayoutController.h new file mode 100644 index 0000000000..45b92ece00 --- /dev/null +++ b/AsyncDisplayKit/Details/ASAbstractLayoutController.h @@ -0,0 +1,20 @@ +/* Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#import +#import + +@interface ASAbstractLayoutController : NSObject + +- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType; + +- (ASRangeTuningParameters)tuningParametersForRangeType:(ASLayoutRangeType)rangeType; + +@property (nonatomic, assign) ASRangeTuningParameters tuningParameters ASDISPLAYNODE_DEPRECATED; + +@end diff --git a/AsyncDisplayKit/Details/ASAbstractLayoutController.mm b/AsyncDisplayKit/Details/ASAbstractLayoutController.mm new file mode 100644 index 0000000000..f18b9b5a95 --- /dev/null +++ b/AsyncDisplayKit/Details/ASAbstractLayoutController.mm @@ -0,0 +1,97 @@ +/* Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#import "ASAbstractLayoutController.h" + +#include +#include +#include + +#import "ASAssert.h" + +@interface ASAbstractLayoutController () { + std::vector _tuningParameters; +} +@end + +@implementation ASAbstractLayoutController + +- (instancetype)init +{ + if (!(self = [super init])) { + return nil; + } + + _tuningParameters = std::vector(ASLayoutRangeTypeCount); + _tuningParameters[ASLayoutRangeTypePreload] = { + .leadingBufferScreenfuls = 2, + .trailingBufferScreenfuls = 1 + }; + _tuningParameters[ASLayoutRangeTypeRender] = { + .leadingBufferScreenfuls = 3, + .trailingBufferScreenfuls = 2 + }; + + return self; +} + +#pragma mark - Tuning Parameters + +- (ASRangeTuningParameters)tuningParametersForRangeType:(ASLayoutRangeType)rangeType +{ + ASDisplayNodeAssert(rangeType < _tuningParameters.size(), @"Requesting a range that is OOB for the configured tuning parameters"); + return _tuningParameters[rangeType]; +} + +- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType +{ + ASDisplayNodeAssert(rangeType < _tuningParameters.size(), @"Requesting a range that is OOB for the configured tuning parameters"); + _tuningParameters[rangeType] = tuningParameters; +} + +// Support for the deprecated tuningParameters property +- (ASRangeTuningParameters)tuningParameters +{ + return [self tuningParametersForRangeType:ASLayoutRangeTypeRender]; +} + +// Support for the deprecated tuningParameters property +- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters +{ + [self setTuningParameters:tuningParameters forRangeType:ASLayoutRangeTypeRender]; +} + +#pragma mark - Index Path Range Support + +// Support for deprecated method +- (BOOL)shouldUpdateForVisibleIndexPath:(NSArray *)indexPaths viewportSize:(CGSize)viewportSize +{ + return [self shouldUpdateForVisibleIndexPaths:indexPaths viewportSize:viewportSize rangeType:ASLayoutRangeTypeRender]; +} + +// Support for the deprecated method +- (NSSet *)indexPathsForScrolling:(ASScrollDirection)scrollDirection viewportSize:(CGSize)viewportSize +{ + return [self indexPathsForScrolling:scrollDirection viewportSize:viewportSize rangeType:ASLayoutRangeTypeRender]; +} + +#pragma mark - Abstract + +- (BOOL)shouldUpdateForVisibleIndexPaths:(NSArray *)indexPaths viewportSize:(CGSize)viewportSize rangeType:(ASLayoutRangeType)rangeType +{ + ASDisplayNodeAssertNotSupported(); + return NO; +} + +- (NSSet *)indexPathsForScrolling:(ASScrollDirection)scrollDirection viewportSize:(CGSize)viewportSize rangeType:(ASLayoutRangeType)rangeType +{ + ASDisplayNodeAssertNotSupported(); + return nil; +} + +@end diff --git a/AsyncDisplayKit/Details/ASFlowLayoutController.h b/AsyncDisplayKit/Details/ASFlowLayoutController.h index 2524c30509..0c682594cb 100644 --- a/AsyncDisplayKit/Details/ASFlowLayoutController.h +++ b/AsyncDisplayKit/Details/ASFlowLayoutController.h @@ -6,7 +6,7 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -#import +#import #import @@ -18,16 +18,10 @@ typedef NS_ENUM(NSUInteger, ASFlowLayoutDirection) { /** * The controller for flow layout. */ -@interface ASFlowLayoutController : NSObject - -- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType; - -- (ASRangeTuningParameters)tuningParametersForRangeType:(ASLayoutRangeType)rangeType; +@interface ASFlowLayoutController : ASAbstractLayoutController @property (nonatomic, readonly, assign) ASFlowLayoutDirection layoutDirection; - (instancetype)initWithScrollOption:(ASFlowLayoutDirection)layoutDirection; -@property (nonatomic, assign) ASRangeTuningParameters tuningParameters ASDISPLAYNODE_DEPRECATED; - @end diff --git a/AsyncDisplayKit/Details/ASFlowLayoutController.mm b/AsyncDisplayKit/Details/ASFlowLayoutController.mm index 024b522db7..bb5370d3bb 100644 --- a/AsyncDisplayKit/Details/ASFlowLayoutController.mm +++ b/AsyncDisplayKit/Details/ASFlowLayoutController.mm @@ -24,8 +24,6 @@ static const CGFloat kASFlowLayoutControllerRefreshingThreshold = 0.3; std::vector> _rangeStartPos; std::vector> _rangeEndPos; - - std::vector _tuningParameters; } @end @@ -39,45 +37,9 @@ static const CGFloat kASFlowLayoutControllerRefreshingThreshold = 0.3; _layoutDirection = layoutDirection; - _tuningParameters = std::vector(ASLayoutRangeTypeCount); - _tuningParameters[ASLayoutRangeTypePreload] = { - .leadingBufferScreenfuls = 2, - .trailingBufferScreenfuls = 1 - }; - _tuningParameters[ASLayoutRangeTypeRender] = { - .leadingBufferScreenfuls = 3, - .trailingBufferScreenfuls = 2 - }; - return self; } -#pragma mark - Tuning Parameters - -- (ASRangeTuningParameters)tuningParametersForRangeType:(ASLayoutRangeType)rangeType -{ - ASDisplayNodeAssert(rangeType < _tuningParameters.size(), @"Requesting a range that is OOB for the configured tuning parameters"); - return _tuningParameters[rangeType]; -} - -- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType -{ - ASDisplayNodeAssert(rangeType < _tuningParameters.size(), @"Requesting a range that is OOB for the configured tuning parameters"); - _tuningParameters[rangeType] = tuningParameters; -} - -// Support for the deprecated tuningParameters property -- (ASRangeTuningParameters)tuningParameters -{ - return [self tuningParametersForRangeType:ASLayoutRangeTypeRender]; -} - -// Support for the deprecated tuningParameters property -- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters -{ - [self setTuningParameters:tuningParameters forRangeType:ASLayoutRangeTypeRender]; -} - #pragma mark - Editing - (void)insertNodesAtIndexPaths:(NSArray *)indexPaths withSizes:(NSArray *)nodeSizes @@ -147,12 +109,6 @@ static const CGFloat kASFlowLayoutControllerRefreshingThreshold = 0.3; ASFlowLayoutDistance(endPos, _visibleRangeEndPos, _nodeSizes) > ASFlowLayoutDistance(_visibleRangeEndPos, rangeEndPos, _nodeSizes) * kASFlowLayoutControllerRefreshingThreshold; } -- (BOOL)shouldUpdateForVisibleIndexPath:(NSArray *)indexPaths - viewportSize:(CGSize)viewportSize -{ - return [self shouldUpdateForVisibleIndexPaths:indexPaths viewportSize:viewportSize rangeType:ASLayoutRangeTypeRender]; -} - - (void)setVisibleNodeIndexPaths:(NSArray *)indexPaths { ASFindIndexPathRange(indexPaths, _visibleRangeStartPos, _visibleRangeEndPos); @@ -203,12 +159,6 @@ static const CGFloat kASFlowLayoutControllerRefreshingThreshold = 0.3; return indexPathSet; } -- (NSSet *)indexPathsForScrolling:(ASScrollDirection)scrollDirection - viewportSize:(CGSize)viewportSize -{ - return [self indexPathsForScrolling:scrollDirection viewportSize:viewportSize rangeType:ASLayoutRangeTypeRender]; -} - #pragma mark - Utility static void ASFindIndexPathRange(NSArray *indexPaths, std::pair &startPos, std::pair &endPos)