[Umbrella] ASCollectionView -> ASCollectionNode Migration, Separate Index Spaces (#2372)

* Separate dataSource & UIKit index spaces

Beef up our supplementary node support

Make the API way better

Go nuts

Add a unit test for UICollectionView's handling of reloadData inside batch updates

Wrap indexPathForNode: in a cache

Convert index paths in delegate methods

Go back on table view

Put collection view back

Switch up the API

Move most ASCollectionView API to ASCollectionNode

Move most table logic over to ASTableNode

Do the things

More conversion work

Keep on keepin' on

Get table view delegate API done

More porting

Simplify

Clear the delegate

More cleanup

Move more stuff around

Remove pointless file

Re-add some API

Put back more API

Use the right flag

* Some cleanup

* Remove incorrect comment

* Tweak the API

* Put back a couple methods

* update example projects (note: ASCollectionView deprecation warnings expected)

* change reloadDataWithCompletion:nil --> reloadData

* Clean up rebase

* Make deprecated numberOfItemsInSection methods optional

* Use the right flag

* Address nits

* update ASDKTube, ASDKgram & ASViewController examples
This commit is contained in:
Adlai Holler
2016-10-14 17:21:16 -07:00
committed by GitHub
parent fb768683bc
commit c2ea7cfeac
50 changed files with 3448 additions and 1122 deletions

View File

@@ -19,6 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
@class ASCellNode;
@protocol ASTableDataSource;
@protocol ASTableDelegate;
@class ASTableNode;
/**
* Asynchronous UITableView with Intelligent Preloading capabilities.
@@ -34,9 +35,37 @@ NS_ASSUME_NONNULL_BEGIN
*/
@interface ASTableView : UITableView
/// The corresponding table node, or nil if one does not exist.
@property (nonatomic, weak, readonly) ASTableNode *tableNode;
@property (nonatomic, weak) id<ASTableDelegate> asyncDelegate;
@property (nonatomic, weak) id<ASTableDataSource> asyncDataSource;
/**
* Retrieves the node for the row at the given index path.
*/
- (nullable ASCellNode *)nodeForRowAtIndexPath:(NSIndexPath *)indexPath AS_WARN_UNUSED_RESULT;
/**
* YES to automatically adjust the contentOffset when cells are inserted or deleted "before"
* visible cells, maintaining the users' visible scroll position. Currently this feature tracks insertions, moves and deletions of
* cells, but section edits are ignored.
*
* default is NO.
*/
@property (nonatomic) BOOL automaticallyAdjustsContentOffset;
/**
* The number of screens left to scroll before the delegate -tableView:beginBatchFetchingWithContext: is called.
*
* Defaults to two screenfuls.
*/
@property (nonatomic, assign) CGFloat leadingScreensForBatching;
@end
@interface ASTableView (Deprecated)
/**
* Initializer.
*
@@ -45,7 +74,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @param style A constant that specifies the style of the table view. See UITableViewStyle for descriptions of valid constants.
*/
- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style;
- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style ASDISPLAYNODE_DEPRECATED;
/**
* Tuning parameters for a range type in full mode.
@@ -57,7 +86,7 @@ NS_ASSUME_NONNULL_BEGIN
* @see ASLayoutRangeMode
* @see ASLayoutRangeType
*/
- (ASRangeTuningParameters)tuningParametersForRangeType:(ASLayoutRangeType)rangeType AS_WARN_UNUSED_RESULT;
- (ASRangeTuningParameters)tuningParametersForRangeType:(ASLayoutRangeType)rangeType AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED;
/**
* Set the tuning parameters for a range type in full mode.
@@ -68,7 +97,7 @@ NS_ASSUME_NONNULL_BEGIN
* @see ASLayoutRangeMode
* @see ASLayoutRangeType
*/
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType;
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType ASDISPLAYNODE_DEPRECATED;
/**
* Tuning parameters for a range type in the specified mode.
@@ -81,7 +110,7 @@ NS_ASSUME_NONNULL_BEGIN
* @see ASLayoutRangeMode
* @see ASLayoutRangeType
*/
- (ASRangeTuningParameters)tuningParametersForRangeMode:(ASLayoutRangeMode)rangeMode rangeType:(ASLayoutRangeType)rangeType AS_WARN_UNUSED_RESULT;
- (ASRangeTuningParameters)tuningParametersForRangeMode:(ASLayoutRangeMode)rangeMode rangeType:(ASLayoutRangeType)rangeType AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED;
/**
* Set the tuning parameters for a range type in the specified mode.
@@ -93,30 +122,39 @@ NS_ASSUME_NONNULL_BEGIN
* @see ASLayoutRangeMode
* @see ASLayoutRangeType
*/
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeMode:(ASLayoutRangeMode)rangeMode rangeType:(ASLayoutRangeType)rangeType;
- (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeMode:(ASLayoutRangeMode)rangeMode rangeType:(ASLayoutRangeType)rangeType ASDISPLAYNODE_DEPRECATED;
/**
* The number of screens left to scroll before the delegate -tableView:beginBatchFetchingWithContext: is called.
* Similar to -visibleCells.
*
* Defaults to two screenfuls.
* @return an array containing the cell nodes being displayed on screen.
*/
@property (nonatomic, assign) CGFloat leadingScreensForBatching;
- (NSArray<ASCellNode *> *)visibleNodes AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED;
/**
* Similar to -indexPathForCell:.
*
* @param cellNode a cellNode part of the table view
*
* @return an indexPath for this cellNode
*/
- (nullable NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED;
/**
* Reload everything from scratch, destroying the working range and all cached nodes.
*
* @param completion block to run on completion of asynchronous loading or nil. If supplied, the block is run on
* @param completion block to run on completion of asynchronous loading or nil. If supplied, the block is run on
* the main thread.
* @warning This method is substantially more expensive than UITableView's version.
*/
-(void)reloadDataWithCompletion:(void (^ _Nullable)())completion;
-(void)reloadDataWithCompletion:(void (^ _Nullable)())completion ASDISPLAYNODE_DEPRECATED;
/**
* Reload everything from scratch, destroying the working range and all cached nodes.
*
* @warning This method is substantially more expensive than UITableView's version.
*/
- (void)reloadData;
- (void)reloadData ASDISPLAYNODE_DEPRECATED;
/**
* Reload everything from scratch entirely on the main thread, destroying the working range and all cached nodes.
@@ -124,25 +162,25 @@ NS_ASSUME_NONNULL_BEGIN
* @warning This method is substantially more expensive than UITableView's version and will block the main thread while
* all the cells load.
*/
- (void)reloadDataImmediately;
- (void)reloadDataImmediately ASDISPLAYNODE_DEPRECATED;
/**
* Triggers a relayout of all nodes.
*
* @discussion This method invalidates and lays out every cell node in the table view.
*/
- (void)relayoutItems;
- (void)relayoutItems ASDISPLAYNODE_DEPRECATED;
/**
* Begins a series of method calls that insert, delete, select, or reload rows and sections of the table view, with animation enabled and no completion block.
*
*
* @discussion You call this method to bracket a series of method calls that ends with endUpdates and that consists of operations
* to insert, delete, select, and reload rows and sections of the table view. When you call endUpdates, ASTableView begins animating
* the operations simultaneously. It's important to remember that the ASTableView will be processing the updates asynchronously after this call is completed.
*
* @warning This method must be called from the main thread.
*/
- (void)beginUpdates;
- (void)beginUpdates ASDISPLAYNODE_DEPRECATED;
/**
* Concludes a series of method calls that insert, delete, select, or reload rows and sections of the table view, with animation enabled and no completion block.
@@ -153,11 +191,11 @@ NS_ASSUME_NONNULL_BEGIN
*
* @warning This method is must be called from the main thread.
*/
- (void)endUpdates;
- (void)endUpdates ASDISPLAYNODE_DEPRECATED;
/**
* Concludes a series of method calls that insert, delete, select, or reload rows and sections of the table view.
* You call this method to bracket a series of method calls that begins with beginUpdates and that consists of operations
* You call this method to bracket a series of method calls that begins with beginUpdates and that consists of operations
* to insert, delete, select, and reload rows and sections of the table view. When you call endUpdates, ASTableView begins animating
* the operations simultaneously. This method is must be called from the main thread. It's important to remember that the ASTableView will
* be processing the updates asynchronously after this call and are not guaranteed to be reflected in the ASTableView until
@@ -168,24 +206,24 @@ NS_ASSUME_NONNULL_BEGIN
* Boolean parameter that contains the value YES if all of the related animations completed successfully or
* NO if they were interrupted. This parameter may be nil. If supplied, the block is run on the main thread.
*/
- (void)endUpdatesAnimated:(BOOL)animated completion:(void (^ _Nullable)(BOOL completed))completion;
- (void)endUpdatesAnimated:(BOOL)animated completion:(void (^ _Nullable)(BOOL completed))completion ASDISPLAYNODE_DEPRECATED;
/**
* Blocks execution of the main thread until all section and row updates are committed. This method must be called from the main thread.
*/
- (void)waitUntilAllUpdatesAreCommitted;
- (void)waitUntilAllUpdatesAreCommitted ASDISPLAYNODE_DEPRECATED;
/**
* Inserts one or more sections, with an option to animate the insertion.
*
* @param sections An index set that specifies the sections to insert.
*
*
* @param animation A constant that indicates how the insertion is to be animated. See UITableViewRowAnimation.
*
* @discussion This method must be called from the main thread. The asyncDataSource must be updated to reflect the changes
* before this method is called.
*/
- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation ASDISPLAYNODE_DEPRECATED;
/**
* Deletes one or more sections, with an option to animate the deletion.
@@ -197,7 +235,7 @@ NS_ASSUME_NONNULL_BEGIN
* @discussion This method must be called from the main thread. The asyncDataSource must be updated to reflect the changes
* before this method is called.
*/
- (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation ASDISPLAYNODE_DEPRECATED;
/**
* Reloads the specified sections using a given animation effect.
@@ -209,7 +247,7 @@ NS_ASSUME_NONNULL_BEGIN
* @discussion This method must be called from the main thread. The asyncDataSource must be updated to reflect the changes
* before this method is called.
*/
- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation ASDISPLAYNODE_DEPRECATED;
/**
* Moves a section to a new location.
@@ -221,7 +259,7 @@ NS_ASSUME_NONNULL_BEGIN
* @discussion This method must be called from the main thread. The asyncDataSource must be updated to reflect the changes
* before this method is called.
*/
- (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection;
- (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection ASDISPLAYNODE_DEPRECATED;
/**
* Inserts rows at the locations identified by an array of index paths, with an option to animate the insertion.
@@ -233,7 +271,7 @@ NS_ASSUME_NONNULL_BEGIN
* @discussion This method must be called from the main thread. The asyncDataSource must be updated to reflect the changes
* before this method is called.
*/
- (void)insertRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
- (void)insertRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation ASDISPLAYNODE_DEPRECATED;
/**
* Deletes the rows specified by an array of index paths, with an option to animate the deletion.
@@ -245,7 +283,7 @@ NS_ASSUME_NONNULL_BEGIN
* @discussion This method must be called from the main thread. The asyncDataSource must be updated to reflect the changes
* before this method is called.
*/
- (void)deleteRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
- (void)deleteRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation ASDISPLAYNODE_DEPRECATED;
/**
* Reloads the specified rows using a given animation effect.
@@ -257,7 +295,7 @@ NS_ASSUME_NONNULL_BEGIN
* @discussion This method must be called from the main thread. The asyncDataSource must be updated to reflect the changes
* before this method is called.
*/
- (void)reloadRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
- (void)reloadRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation ASDISPLAYNODE_DEPRECATED;
/**
* Moves the row at a specified location to a destination location.
@@ -269,213 +307,21 @@ NS_ASSUME_NONNULL_BEGIN
* @discussion This method must be called from the main thread. The asyncDataSource must be updated to reflect the changes
* before this method is called.
*/
- (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath;
- (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath ASDISPLAYNODE_DEPRECATED;
/**
* Similar to -cellForRowAtIndexPath:.
*
* @param indexPath The index path of the requested node.
*
* @return a node for display at this indexpath.
*/
- (ASCellNode *)nodeForRowAtIndexPath:(NSIndexPath *)indexPath AS_WARN_UNUSED_RESULT;
/// Deprecated in 2.0. You should not call this method.
- (void)clearContents ASDISPLAYNODE_DEPRECATED;
/**
* Similar to -indexPathForCell:.
*
* @param cellNode a cellNode part of the table view
*
* @return an indexPath for this cellNode
*/
- (nullable NSIndexPath *)indexPathForNode:(ASCellNode *)cellNode AS_WARN_UNUSED_RESULT;
/**
* Similar to -visibleCells.
*
* @return an array containing the cell nodes being displayed on screen.
*/
- (NSArray<ASCellNode *> *)visibleNodes AS_WARN_UNUSED_RESULT;
/**
* YES to automatically adjust the contentOffset when cells are inserted or deleted "before"
* visible cells, maintaining the users' visible scroll position. Currently this feature tracks insertions, moves and deletions of
* cells, but section edits are ignored.
*
* default is NO.
*/
@property (nonatomic) BOOL automaticallyAdjustsContentOffset;
/**
* Triggers all loaded ASCellNodes to destroy displayed contents (freeing a lot of memory).
*
* @discussion This method should only be called by ASTableNode. To be removed in a later release.
*/
- (void)clearContents;
/**
* Triggers all loaded ASCellNodes to purge any data fetched from the network or disk (freeing memory).
*
* @discussion This method should only be called by ASTableNode. To be removed in a later release.
*/
- (void)clearFetchedData;
@end
/**
* This is a node-based UITableViewDataSource.
*/
@protocol ASTableDataSource <ASCommonTableViewDataSource, NSObject>
@optional
/**
* Similar to -tableView:cellForRowAtIndexPath:.
*
* @param tableView The sender.
*
* @param indexPath The index path of the requested node.
*
* @return a node for display at this indexpath. This will be called on the main thread and should not implement reuse (it will be called once per row). Unlike UITableView's version, this method
* is not called when the row is about to display.
*/
- (ASCellNode *)tableView:(ASTableView *)tableView nodeForRowAtIndexPath:(NSIndexPath *)indexPath AS_WARN_UNUSED_RESULT;
/**
* Similar to -tableView:nodeForRowAtIndexPath:
* This method takes precedence over tableView:nodeForRowAtIndexPath: if implemented.
* @param tableView The sender.
*
* @param indexPath The index path of the requested node.
*
* @return a block that creates the node for display at this indexpath.
* Must be thread-safe (can be called on the main thread or a background
* queue) and should not implement reuse (it will be called once per row).
*/
- (ASCellNodeBlock)tableView:(ASTableView *)tableView nodeBlockForRowAtIndexPath:(NSIndexPath *)indexPath AS_WARN_UNUSED_RESULT;
/**
* Indicator to lock the data source for data fetching in async mode.
* We should not update the data source until the data source has been unlocked. Otherwise, it will incur data inconsistency or exception
* due to the data access in async mode.
*
* @param tableView The sender.
* @deprecated The data source is always accessed on the main thread, and this method will not be called.
*/
- (void)tableViewLockDataSource:(ASTableView *)tableView ASDISPLAYNODE_DEPRECATED;
/**
* Indicator to unlock the data source for data fetching in asyn mode.
* We should not update the data source until the data source has been unlocked. Otherwise, it will incur data inconsistency or exception
* due to the data access in async mode.
*
* @param tableView The sender.
* @deprecated The data source is always accessed on the main thread, and this method will not be called.
*/
- (void)tableViewUnlockDataSource:(ASTableView *)tableView ASDISPLAYNODE_DEPRECATED;
/// Deprecated in 2.0. You should not call this method.
- (void)clearFetchedData ASDISPLAYNODE_DEPRECATED;
@end
ASDISPLAYNODE_DEPRECATED
@protocol ASTableViewDataSource <ASTableDataSource>
@end
/**
* This is a node-based UITableViewDelegate.
*
* Note that -tableView:heightForRowAtIndexPath: has been removed; instead, your custom ASCellNode subclasses are
* responsible for deciding their preferred onscreen height in -calculateSizeThatFits:.
*/
@protocol ASTableDelegate <ASCommonTableViewDelegate, NSObject>
@optional
/**
* Informs the delegate that the table view will add the given node
* at the given index path to the view hierarchy.
*
* @param tableView The sender.
* @param node The node that will be displayed.
* @param indexPath The index path of the row that will be displayed.
*
* @warning AsyncDisplayKit processes table view edits asynchronously. The index path
* passed into this method may not correspond to the same item in your data source
* if your data source has been updated since the last edit was processed.
*/
- (void)tableView:(ASTableView *)tableView willDisplayNode:(ASCellNode *)node forRowAtIndexPath:(NSIndexPath *)indexPath;
/**
* Informs the delegate that the table view did remove the provided node from the view hierarchy.
* This may be caused by the node scrolling out of view, or by deleting the row
* or its containing section with @c deleteRowsAtIndexPaths:withRowAnimation: or @c deleteSections:withRowAnimation: .
*
* @param tableView The sender.
* @param node The node which was removed from the view hierarchy.
* @param indexPath The index path at which the node was located before the removal.
*
* @warning AsyncDisplayKit processes table view edits asynchronously. The index path
* passed into this method may not correspond to the same item in your data source
* if your data source has been updated since the last edit was processed.
*/
- (void)tableView:(ASTableView *)tableView didEndDisplayingNode:(ASCellNode *)node forRowAtIndexPath:(NSIndexPath *)indexPath;
/**
* Receive a message that the tableView is near the end of its data set and more data should be fetched if necessary.
*
* @param tableView The sender.
* @param context A context object that must be notified when the batch fetch is completed.
*
* @discussion You must eventually call -completeBatchFetching: with an argument of YES in order to receive future
* notifications to do batch fetches. This method is called on a background queue.
*
* ASTableView currently only supports batch events for tail loads. If you require a head load, consider implementing a
* UIRefreshControl.
*/
- (void)tableView:(ASTableView *)tableView willBeginBatchFetchWithContext:(ASBatchContext *)context;
/**
* Tell the tableView if batch fetching should begin.
*
* @param tableView The sender.
*
* @discussion Use this method to conditionally fetch batches. Example use cases are: limiting the total number of
* objects that can be fetched or no network connection.
*
* If not implemented, the tableView assumes that it should notify its asyncDelegate when batch fetching
* should occur.
*/
- (BOOL)shouldBatchFetchForTableView:(ASTableView *)tableView AS_WARN_UNUSED_RESULT;
/**
* Provides the constrained size range for measuring the row at the index path.
* Note: the widths in the returned size range are ignored!
*
* @param tableView The sender.
*
* @param indexPath The index path of the node.
*
* @return A constrained size range for layout the node at this index path.
*/
- (ASSizeRange)tableView:(ASTableView *)tableView constrainedSizeForRowAtIndexPath:(NSIndexPath *)indexPath AS_WARN_UNUSED_RESULT;
/**
* Informs the delegate that the table view will add the node
* at the given index path to the view hierarchy.
*
* @param tableView The sender.
* @param indexPath The index path of the row that will be displayed.
*
* @warning AsyncDisplayKit processes table view edits asynchronously. The index path
* passed into this method may not correspond to the same item in your data source
* if your data source has been updated since the last edit was processed.
*
* This method is deprecated. Use @c tableView:willDisplayNode:forRowAtIndexPath: instead.
*/
- (void)tableView:(ASTableView *)tableView willDisplayNodeForRowAtIndexPath:(NSIndexPath *)indexPath ASDISPLAYNODE_DEPRECATED;
@end
ASDISPLAYNODE_DEPRECATED
@protocol ASTableViewDelegate <ASTableDelegate>
@end