From aaf3aeff5b22dbf7331eb08914c5352fbdbf0867 Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Mon, 3 Oct 2016 14:22:21 -0700 Subject: [PATCH] Start deprecating begin/end updates --- AsyncDisplayKit/ASCollectionNode+Beta.h | 6 +-- AsyncDisplayKit/ASTableView.h | 61 +++++++++++++------------ AsyncDisplayKit/ASTableView.mm | 11 +++++ 3 files changed, 47 insertions(+), 31 deletions(-) diff --git a/AsyncDisplayKit/ASCollectionNode+Beta.h b/AsyncDisplayKit/ASCollectionNode+Beta.h index 293d04bf..ce9c3c81 100644 --- a/AsyncDisplayKit/ASCollectionNode+Beta.h +++ b/AsyncDisplayKit/ASCollectionNode+Beta.h @@ -17,11 +17,11 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout layoutFacilitator:(nullable id)layoutFacilitator; -- (void)beginUpdates; +- (void)beginUpdates ASDISPLAYNODE_DEPRECATED; -- (void)endUpdatesAnimated:(BOOL)animated; +- (void)endUpdatesAnimated:(BOOL)animated ASDISPLAYNODE_DEPRECATED; -- (void)endUpdatesAnimated:(BOOL)animated completion:(void (^)(BOOL))completion; +- (void)endUpdatesAnimated:(BOOL)animated completion:(void (^)(BOOL))completion ASDISPLAYNODE_DEPRECATED; @end diff --git a/AsyncDisplayKit/ASTableView.h b/AsyncDisplayKit/ASTableView.h index 5e97c744..c18435a7 100644 --- a/AsyncDisplayKit/ASTableView.h +++ b/AsyncDisplayKit/ASTableView.h @@ -132,34 +132,7 @@ NS_ASSUME_NONNULL_BEGIN */ - (void)relayoutItems; -/** - * begins a batch of insert, delete reload and move operations. This method must be called from the main thread. - */ -- (void)beginUpdates; - -/** - * 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. - * 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 is completed. - */ -- (void)endUpdates; - -/** - * 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 - * 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 - * the completion block is executed. - * - * @param animated NO to disable all animations. - * @param completion A completion handler block to execute when all of the operations are finished. This block takes a single - * 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)performBatchAnimated:(BOOL)animated updates:(__attribute((noescape)) void(^)())updateBlock completion:(nullable void(^)(BOOL finished))completion; /** * Blocks execution of the main thread until all section and row updates are committed. This method must be called from the main thread. @@ -312,6 +285,38 @@ NS_ASSUME_NONNULL_BEGIN @end +@interface ASTableView (Deprecated) + +/** + * begins a batch of insert, delete reload and move operations. This method must be called from the main thread. + */ +- (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. + * 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 is completed. + */ +- (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 + * 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 + * the completion block is executed. + * + * @param animated NO to disable all animations. + * @param completion A completion handler block to execute when all of the operations are finished. This block takes a single + * 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 ASDISPLAYNODE_DEPRECATED; + +@end /** * This is a node-based UITableViewDataSource. diff --git a/AsyncDisplayKit/ASTableView.mm b/AsyncDisplayKit/ASTableView.mm index 9f671f9e..4de90b0e 100644 --- a/AsyncDisplayKit/ASTableView.mm +++ b/AsyncDisplayKit/ASTableView.mm @@ -427,6 +427,17 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; return visibleNodes; } +- (void)performBatchAnimated:(BOOL)animated updates:(void (^)())updateBlock completion:(void (^)(BOOL))completion +{ + ASDisplayNodeAssertMainThread(); +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + [self beginUpdates]; + updateBlock(); + [self endUpdatesAnimated:animated completion:completion]; +#pragma clang diagnostic pop +} + - (void)beginUpdates { ASDisplayNodeAssertMainThread();