From 3f509dbd2f1024ee2edc2039a0b1679081c74484 Mon Sep 17 00:00:00 2001 From: Ethan Nagel Date: Thu, 26 Mar 2015 16:32:44 -0700 Subject: [PATCH 1/3] add completion block to reloadData methods --- AsyncDisplayKit/ASCollectionView.h | 8 ++++++++ AsyncDisplayKit/ASCollectionView.mm | 9 +++++++-- AsyncDisplayKit/ASTableView.h | 8 ++++++++ AsyncDisplayKit/ASTableView.mm | 9 +++++++-- AsyncDisplayKit/Details/ASDataController.h | 2 +- AsyncDisplayKit/Details/ASDataController.mm | 6 +++++- 6 files changed, 36 insertions(+), 6 deletions(-) diff --git a/AsyncDisplayKit/ASCollectionView.h b/AsyncDisplayKit/ASCollectionView.h index b99f55a7da..de9bf0df92 100644 --- a/AsyncDisplayKit/ASCollectionView.h +++ b/AsyncDisplayKit/ASCollectionView.h @@ -70,6 +70,14 @@ */ @property (nonatomic, assign) CGFloat leadingScreensForBatching; +/** + * Reload everything from scratch, destroying the working range and all cached nodes. + * + * @param completion Block to run on completion or nil. + * @warning This method is substantially more expensive than UICollectionView's version. + */ +- (void)reloadDataWithCompletion:(void (^)())completion; + /** * Reload everything from scratch, destroying the working range and all cached nodes. * diff --git a/AsyncDisplayKit/ASCollectionView.mm b/AsyncDisplayKit/ASCollectionView.mm index 80786df40d..04200238bf 100644 --- a/AsyncDisplayKit/ASCollectionView.mm +++ b/AsyncDisplayKit/ASCollectionView.mm @@ -162,13 +162,18 @@ - (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionVi #pragma mark - #pragma mark Overrides. -- (void)reloadData +- (void)reloadDataWithCompletion:(void (^)())completion { ASDisplayNodeAssert(self.asyncDelegate, @"ASCollectionView's asyncDelegate property must be set."); ASDisplayNodePerformBlockOnMainThread(^{ [super reloadData]; }); - [_dataController reloadDataWithAnimationOption:kASCollectionViewAnimationNone]; + [_dataController reloadDataWithAnimationOption:kASCollectionViewAnimationNone completion:completion]; +} + +- (void)reloadData +{ + [self reloadDataWithCompletion:nil]; } - (void)setDataSource:(id)dataSource diff --git a/AsyncDisplayKit/ASTableView.h b/AsyncDisplayKit/ASTableView.h index f783a5e880..01415b29ca 100644 --- a/AsyncDisplayKit/ASTableView.h +++ b/AsyncDisplayKit/ASTableView.h @@ -70,6 +70,14 @@ */ @property (nonatomic, assign) CGFloat leadingScreensForBatching; +/** + * Reload everything from scratch, destroying the working range and all cached nodes. + * + * @param completion Block to run on completion or nil. + * @warning This method is substantially more expensive than UITableView's version. + */ +-(void)reloadDataWithCompletion:(void (^)())completion; + /** * Reload everything from scratch, destroying the working range and all cached nodes. * diff --git a/AsyncDisplayKit/ASTableView.mm b/AsyncDisplayKit/ASTableView.mm index 4c2b79ca01..ff2410eab0 100644 --- a/AsyncDisplayKit/ASTableView.mm +++ b/AsyncDisplayKit/ASTableView.mm @@ -205,13 +205,18 @@ - (void)setAsyncDelegate:(id)asyncDelegate } } -- (void)reloadData +- (void)reloadDataWithCompletion:(void (^)())completion { ASDisplayNodeAssert(self.asyncDelegate, @"ASTableView's asyncDelegate property must be set."); ASDisplayNodePerformBlockOnMainThread(^{ [super reloadData]; }); - [_dataController reloadDataWithAnimationOption:UITableViewRowAnimationNone]; + [_dataController reloadDataWithAnimationOption:UITableViewRowAnimationNone completion:completion]; +} + +- (void)reloadData +{ + [self reloadDataWithCompletion:nil]; } - (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeType:(ASLayoutRangeType)rangeType diff --git a/AsyncDisplayKit/Details/ASDataController.h b/AsyncDisplayKit/Details/ASDataController.h index 996d84427f..f8f8fca202 100644 --- a/AsyncDisplayKit/Details/ASDataController.h +++ b/AsyncDisplayKit/Details/ASDataController.h @@ -155,7 +155,7 @@ typedef NSUInteger ASDataControllerAnimationOptions; - (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath withAnimationOption:(ASDataControllerAnimationOptions)animationOption;; -- (void)reloadDataWithAnimationOption:(ASDataControllerAnimationOptions)animationOption;; +- (void)reloadDataWithAnimationOption:(ASDataControllerAnimationOptions)animationOption completion:(void (^)())completion; /** @name Data Querying */ diff --git a/AsyncDisplayKit/Details/ASDataController.mm b/AsyncDisplayKit/Details/ASDataController.mm index ed70155727..8ba124286f 100644 --- a/AsyncDisplayKit/Details/ASDataController.mm +++ b/AsyncDisplayKit/Details/ASDataController.mm @@ -437,7 +437,7 @@ - (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)n }); } -- (void)reloadDataWithAnimationOption:(ASDataControllerAnimationOptions)animationOption +- (void)reloadDataWithAnimationOption:(ASDataControllerAnimationOptions)animationOption completion:(void (^)())completion { [self performDataFetchingWithBlock:^{ // Fetching data in calling thread @@ -478,6 +478,10 @@ - (void)reloadDataWithAnimationOption:(ASDataControllerAnimationOptions)animatio }]; [self _batchInsertNodes:updatedNodes atIndexPaths:updatedIndexPaths withAnimationOptions:animationOption]; + + if (completion) { + dispatch_async(dispatch_get_main_queue(), completion); + } }); }]; } From abd725d8c149b50c1e3989d80ae0106a9cbbb9b0 Mon Sep 17 00:00:00 2001 From: Ethan Nagel Date: Fri, 27 Mar 2015 18:14:05 -0700 Subject: [PATCH 2/3] update documentation for reloadData:completion --- AsyncDisplayKit/ASCollectionView.h | 3 ++- AsyncDisplayKit/ASTableView.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/AsyncDisplayKit/ASCollectionView.h b/AsyncDisplayKit/ASCollectionView.h index de9bf0df92..cb5bfd33dc 100644 --- a/AsyncDisplayKit/ASCollectionView.h +++ b/AsyncDisplayKit/ASCollectionView.h @@ -73,7 +73,8 @@ /** * Reload everything from scratch, destroying the working range and all cached nodes. * - * @param completion Block to run on completion or nil. + * @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 UICollectionView's version. */ - (void)reloadDataWithCompletion:(void (^)())completion; diff --git a/AsyncDisplayKit/ASTableView.h b/AsyncDisplayKit/ASTableView.h index 01415b29ca..8b399a01b4 100644 --- a/AsyncDisplayKit/ASTableView.h +++ b/AsyncDisplayKit/ASTableView.h @@ -73,7 +73,8 @@ /** * Reload everything from scratch, destroying the working range and all cached nodes. * - * @param completion Block to run on completion or nil. + * @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 (^)())completion; From 04ec6025000bacabb77098570b51ce18d18889d1 Mon Sep 17 00:00:00 2001 From: rlasante Date: Fri, 1 May 2015 13:04:26 -0400 Subject: [PATCH 3/3] =?UTF-8?q?Don=E2=80=99t=20retain=20an=20action?= =?UTF-8?q?=E2=80=99s=20target=20in=20ASControlNode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - addTarget:action:forControlEvents: should not retain the target. If it does then there is a very high likelihood of a retain cycle. --- AsyncDisplayKit/ASControlNode.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AsyncDisplayKit/ASControlNode.m b/AsyncDisplayKit/ASControlNode.m index f423c33606..8a5d89ed11 100644 --- a/AsyncDisplayKit/ASControlNode.m +++ b/AsyncDisplayKit/ASControlNode.m @@ -226,7 +226,7 @@ - (void)addTarget:(id)target action:(SEL)action forControlEvents:(ASControlNodeE if (!eventDispatchTable) { // Create the dispatch table for this event. - eventDispatchTable = [NSMapTable strongToStrongObjectsMapTable]; + eventDispatchTable = [NSMapTable weakToStrongObjectsMapTable]; [_controlEventDispatchTable setObject:eventDispatchTable forKey:eventKey]; }