From 2f7925544b8b39b982d890a80373d87209cf603b Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Wed, 28 Dec 2016 11:22:43 -0600 Subject: [PATCH] Add a failing unit test for the automatic subnode management range issue (#2826) --- AsyncDisplayKit/ASCellNode.h | 7 ++++- AsyncDisplayKit/ASCellNode.mm | 9 +----- AsyncDisplayKitTests/ASCollectionViewTests.mm | 28 +++++++++++++++++++ 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/AsyncDisplayKit/ASCellNode.h b/AsyncDisplayKit/ASCellNode.h index d5ae55aec4..219b197716 100644 --- a/AsyncDisplayKit/ASCellNode.h +++ b/AsyncDisplayKit/ASCellNode.h @@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN -@class ASCellNode; +@class ASCellNode, ASTextNode; typedef NSUInteger ASCellNodeAnimation; @@ -205,6 +205,11 @@ typedef NS_ENUM(NSUInteger, ASCellNodeVisibilityEvent) { */ @property (nonatomic, assign) UIEdgeInsets textInsets; +/** + * The text node used by this cell node. + */ +@property (nonatomic, strong, readonly) ASTextNode *textNode; + @end NS_ASSUME_NONNULL_END diff --git a/AsyncDisplayKit/ASCellNode.mm b/AsyncDisplayKit/ASCellNode.mm index 2faef39c01..16a5b22d40 100644 --- a/AsyncDisplayKit/ASCellNode.mm +++ b/AsyncDisplayKit/ASCellNode.mm @@ -395,13 +395,6 @@ static NSMutableSet *__cellClassesForVisibilityNotifications = nil; // See +init #pragma mark - #pragma mark ASTextCellNode -@interface ASTextCellNode () - -@property (nonatomic, strong) ASTextNode *textNode; - -@end - - @implementation ASTextCellNode static const CGFloat kASTextCellNodeDefaultFontSize = 18.0f; @@ -420,7 +413,7 @@ static const CGFloat kASTextCellNodeDefaultVerticalPadding = 11.0f; _textInsets = textInsets; _textAttributes = [textAttributes copy]; _textNode = [[ASTextNode alloc] init]; - [self addSubnode:_textNode]; + self.automaticallyManagesSubnodes = YES; } return self; } diff --git a/AsyncDisplayKitTests/ASCollectionViewTests.mm b/AsyncDisplayKitTests/ASCollectionViewTests.mm index 4d67f5a6e8..60ae5961d1 100644 --- a/AsyncDisplayKitTests/ASCollectionViewTests.mm +++ b/AsyncDisplayKitTests/ASCollectionViewTests.mm @@ -1024,4 +1024,32 @@ XCTAssertEqual([[cn valueForKeyPath:@"rangeController.currentRangeMode"] integerValue], ASLayoutRangeModeMinimum, @"Expected range mode to be minimum before scrolling begins."); } +/** + * This tests an issue where, since subnode insertions aren't applied until the UIKit layout pass, + * which we trigger during the display phase, subnodes like network image nodes are not preloading + * until this layout pass happens which is too late. + */ +- (void)DISABLED_testThatAutomaticallyManagedSubnodesGetPreloadCallBeforeDisplay +{ + UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; + ASCollectionViewTestController *testController = [[ASCollectionViewTestController alloc] initWithNibName:nil bundle:nil]; + window.rootViewController = testController; + ASCollectionNode *cn = testController.collectionNode; + + __block NSInteger itemCount = 100; + testController.asyncDelegate->_itemCounts = {itemCount}; + [window makeKeyAndVisible]; + [window layoutIfNeeded]; + + [cn waitUntilAllUpdatesAreCommitted]; + for (NSInteger i = 0; i < itemCount; i++) { + ASTextCellNodeWithSetSelectedCounter *node = [cn nodeForItemAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]]; + XCTAssert(node.automaticallyManagesSubnodes, @"Expected test cell node to use automatic subnode management. Can modify the test with a different class if needed."); + ASDisplayNode *subnode = node.textNode; + XCTAssertEqualObjects(NSStringFromASInterfaceState(subnode.interfaceState), NSStringFromASInterfaceState(node.interfaceState), @"Subtree interface state should match cell node interface state for ASM nodes."); + XCTAssert(node.inDisplayState || !node.nodeLoaded, @"Only nodes in the display range should be loaded."); + } + +} + @end