-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix double-load issue with ASCollectionNode #372
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
#import <AsyncDisplayKit/ASDisplayNode+FrameworkPrivate.h> | ||
#import <AsyncDisplayKit/ASInternalHelpers.h> | ||
#import <AsyncDisplayKit/ASCellNode+Internal.h> | ||
#import <AsyncDisplayKit/_ASHierarchyChangeSet.h> | ||
#import <AsyncDisplayKit/AsyncDisplayKit+Debug.h> | ||
#import <AsyncDisplayKit/ASSectionContext.h> | ||
#import <AsyncDisplayKit/ASDataController.h> | ||
|
@@ -682,24 +683,34 @@ - (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 | ||
{ | ||
[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]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I swapped the order of these two methods to group the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know the original code doesn't assert main thread and check if this node is loaded, should we do these now? |
||
} | ||
|
||
- (void)beginUpdates | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,7 +259,8 @@ - (void)testSelection | |
[window setRootViewController:testController]; | ||
[window makeKeyAndVisible]; | ||
|
||
[testController.collectionView reloadDataImmediately]; | ||
[testController.collectionNode reloadData]; | ||
[testController.collectionNode waitUntilAllUpdatesAreCommitted]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No because it's deprecated. |
||
[testController.collectionView layoutIfNeeded]; | ||
|
||
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:0]; | ||
|
@@ -390,12 +391,13 @@ - (void)testThatCollectionNodeConformsToExpectedProtocols | |
ASCollectionViewTestController *testController = [[ASCollectionViewTestController alloc] initWithNibName:nil bundle:nil];\ | ||
__unused ASCollectionViewTestDelegate *del = testController.asyncDelegate;\ | ||
__unused ASCollectionView *cv = testController.collectionView;\ | ||
__unused ASCollectionNode *cn = testController.collectionNode;\ | ||
ASCollectionNode *cn = testController.collectionNode;\ | ||
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];\ | ||
[window makeKeyAndVisible]; \ | ||
window.rootViewController = testController;\ | ||
\ | ||
[testController.collectionView reloadDataImmediately];\ | ||
[cn reloadData];\ | ||
[cn waitUntilAllUpdatesAreCommitted]; \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No because it's deprecated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it 👍 |
||
[testController.collectionView layoutIfNeeded]; | ||
|
||
- (void)testThatSubmittingAValidInsertDoesNotThrowAnException | ||
|
@@ -620,7 +622,7 @@ - (void)testThatDisappearingSupplementariesWithLayerBackedNodesDontFailAssert | |
for (NSInteger i = 0; i < 2; i++) { | ||
// NOTE: waitUntilAllUpdatesAreCommitted or reloadDataImmediately is not sufficient here!! | ||
XCTestExpectation *done = [self expectationWithDescription:[NSString stringWithFormat:@"Reload #%td complete", i]]; | ||
[cv reloadDataWithCompletion:^{ | ||
[cn reloadDataWithCompletion:^{ | ||
[done fulfill]; | ||
}]; | ||
[self waitForExpectationsWithTimeout:1 handler:nil]; | ||
|
@@ -752,7 +754,8 @@ - (void)testThatSectionContextsAreCorrectAfterReloadData | |
updateValidationTestPrologue | ||
|
||
del.sectionGeneration++; | ||
[cv reloadDataImmediately]; | ||
[cn reloadData]; | ||
[cn waitUntilAllUpdatesAreCommitted]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No because it's deprecated. |
||
|
||
NSInteger sectionCount = del->_itemCounts.size(); | ||
for (NSInteger section = 0; section < sectionCount; section++) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation copied from
ASCollectionView
.