From e3b91eab697ff5f9bdf56e59991f5a7485607b2e Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Mon, 19 Jun 2017 11:19:06 -0700 Subject: [PATCH 1/4] Fix double-reload issue with ASCollectionNode --- Source/ASCollectionNode.mm | 23 ++++++--- Source/ASCollectionView.h | 6 +-- Source/ASCollectionView.mm | 51 ++++++------------- Source/Details/ASCollectionInternal.h | 5 ++ .../Private/ASCollectionView+Undeprecated.h | 24 --------- Tests/ASCollectionModernDataSourceTests.m | 32 +++++++----- Tests/ASCollectionViewTests.mm | 13 +++-- 7 files changed, 66 insertions(+), 88 deletions(-) diff --git a/Source/ASCollectionNode.mm b/Source/ASCollectionNode.mm index 3412dd67e..69912ab5e 100644 --- a/Source/ASCollectionNode.mm +++ b/Source/ASCollectionNode.mm @@ -28,6 +28,7 @@ #import #import #import +#import #import #import #import @@ -682,9 +683,17 @@ - (void)waitUntilAllUpdatesAreCommitted - (void)reloadDataWithCompletion:(void (^)())completion { ASDisplayNodeAssertMainThread(); - if (self.nodeLoaded) { - [self.view reloadDataWithCompletion:completion]; + if (!self.nodeLoaded) { + return; } + + [self performBatchUpdates:^{ + [self.view.changeSet reloadData]; + } completion:^(BOOL finished){ + if (completion) { + completion(); + } + }]; } - (void)reloadData @@ -692,14 +701,16 @@ - (void)reloadData [self reloadDataWithCompletion:nil]; } -- (void)relayoutItems +- (void)reloadDataImmediately { - [self.view relayoutItems]; + ASDisplayNodeAssertMainThread(); + [self reloadData]; + [self waitUntilAllUpdatesAreCommitted]; } -- (void)reloadDataImmediately +- (void)relayoutItems { - [self.view reloadDataImmediately]; + [self.view relayoutItems]; } - (void)beginUpdates diff --git a/Source/ASCollectionView.h b/Source/ASCollectionView.h index 2972ced49..b2f015cf5 100644 --- a/Source/ASCollectionView.h +++ b/Source/ASCollectionView.h @@ -266,14 +266,14 @@ NS_ASSUME_NONNULL_BEGIN * the main thread. * @warning This method is substantially more expensive than UICollectionView's version. */ -- (void)reloadDataWithCompletion:(nullable void (^)())completion ASDISPLAYNODE_DEPRECATED_MSG("Use ASCollectionNode method instead."); +- (void)reloadDataWithCompletion:(nullable void (^)())completion AS_UNAVAILABLE("Use ASCollectionNode method instead."); /** * Reload everything from scratch, destroying the working range and all cached nodes. * * @warning This method is substantially more expensive than UICollectionView's version. */ -- (void)reloadData ASDISPLAYNODE_DEPRECATED_MSG("Use ASCollectionNode method instead."); +- (void)reloadData AS_UNAVAILABLE("Use ASCollectionNode method instead."); /** * Reload everything from scratch entirely on the main thread, destroying the working range and all cached nodes. @@ -281,7 +281,7 @@ NS_ASSUME_NONNULL_BEGIN * @warning This method is substantially more expensive than UICollectionView's version and will block the main thread * while all the cells load. */ -- (void)reloadDataImmediately ASDISPLAYNODE_DEPRECATED_MSG("Use ASCollectionNode's -reloadDataWithCompletion: followed by -waitUntilAllUpdatesAreCommitted instead."); +- (void)reloadDataImmediately AS_UNAVAILABLE("Use ASCollectionNode method instead."); /** * Triggers a relayout of all nodes. diff --git a/Source/ASCollectionView.mm b/Source/ASCollectionView.mm index 68b4c3468..906268349 100644 --- a/Source/ASCollectionView.mm +++ b/Source/ASCollectionView.mm @@ -144,11 +144,6 @@ @interface ASCollectionView () _itemCounts.size(); for (NSInteger section = 0; section < sectionCount; section++) { From 12404b3d90be5ec6aa3e4c7ea977274d89322f17 Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Mon, 19 Jun 2017 11:24:00 -0700 Subject: [PATCH 2/4] Add a message to the change pile --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e26c62f89..fb5adc85a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - [Yoga] Implement ASYogaLayoutSpec, a simplified integration strategy for Yoga-powered layout calculation. [Scott Goodson](https://github.com/appleguy) - Fixed an issue where calls to setNeedsDisplay and setNeedsLayout would stop working on loaded nodes. [Garrett Moon](https://github.com/garrettmoon) - Migrated unit tests to OCMock 3.4 (from 2.2) and improved the multiplex image node tests. [Adlai Holler](https://github.com/Adlai-Holler) +- Fix CollectionNode double-load issue. This should significantly improve performance in cases where a collection node has content immediately available on first layout i.e. not fetched from the network. [Adlai Holler](https://github.com/Adlai-Holler) ## 2.3.3 - [ASTextKitFontSizeAdjuster] Replace use of NSAttributedString's boundingRectWithSize:options:context: with NSLayoutManager's boundingRectForGlyphRange:inTextContainer: [Ricky Cancro](https://github.com/rcancro) From b71d643a00feaf205e3a55bdf1213abbf743b6b6 Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Mon, 19 Jun 2017 11:29:29 -0700 Subject: [PATCH 3/4] Fix some license headers --- Tests/ASCollectionViewTests.mm | 2 +- Tests/ASDisplayNodeLayoutTests.mm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/ASCollectionViewTests.mm b/Tests/ASCollectionViewTests.mm index ca2b45cb0..00cf58d2b 100644 --- a/Tests/ASCollectionViewTests.mm +++ b/Tests/ASCollectionViewTests.mm @@ -1,5 +1,5 @@ // -// ASCollectionViewTests.m +// ASCollectionViewTests.mm // Texture // // Copyright (c) 2014-present, Facebook, Inc. All rights reserved. diff --git a/Tests/ASDisplayNodeLayoutTests.mm b/Tests/ASDisplayNodeLayoutTests.mm index 202b3b4fa..8688e5cec 100644 --- a/Tests/ASDisplayNodeLayoutTests.mm +++ b/Tests/ASDisplayNodeLayoutTests.mm @@ -1,5 +1,5 @@ // -// ASDisplayNodeLayoutTests.m +// ASDisplayNodeLayoutTests.mm // Texture // // Copyright (c) 2014-present, Facebook, Inc. All rights reserved. From 65cf7a9a45b3c9df32755ae5503eb2dd4d277967 Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Mon, 19 Jun 2017 13:52:52 -0700 Subject: [PATCH 4/4] Address feedback --- Source/ASCollectionNode.mm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/ASCollectionNode.mm b/Source/ASCollectionNode.mm index 69912ab5e..6c7e3799c 100644 --- a/Source/ASCollectionNode.mm +++ b/Source/ASCollectionNode.mm @@ -710,7 +710,10 @@ - (void)reloadDataImmediately - (void)relayoutItems { - [self.view relayoutItems]; + ASDisplayNodeAssertMainThread(); + if (self.nodeLoaded) { + [self.view relayoutItems]; + } } - (void)beginUpdates