Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 2f79255

Browse files
author
Adlai Holler
authored
Add a failing unit test for the automatic subnode management range issue (#2826)
1 parent e264d94 commit 2f79255

3 files changed

Lines changed: 35 additions & 9 deletions

File tree

AsyncDisplayKit/ASCellNode.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
NS_ASSUME_NONNULL_BEGIN
1414

15-
@class ASCellNode;
15+
@class ASCellNode, ASTextNode;
1616

1717
typedef NSUInteger ASCellNodeAnimation;
1818

@@ -205,6 +205,11 @@ typedef NS_ENUM(NSUInteger, ASCellNodeVisibilityEvent) {
205205
*/
206206
@property (nonatomic, assign) UIEdgeInsets textInsets;
207207

208+
/**
209+
* The text node used by this cell node.
210+
*/
211+
@property (nonatomic, strong, readonly) ASTextNode *textNode;
212+
208213
@end
209214

210215
NS_ASSUME_NONNULL_END

AsyncDisplayKit/ASCellNode.mm

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -395,13 +395,6 @@ - (void)handleVisibilityChange:(BOOL)isVisible
395395
#pragma mark -
396396
#pragma mark ASTextCellNode
397397

398-
@interface ASTextCellNode ()
399-
400-
@property (nonatomic, strong) ASTextNode *textNode;
401-
402-
@end
403-
404-
405398
@implementation ASTextCellNode
406399

407400
static const CGFloat kASTextCellNodeDefaultFontSize = 18.0f;
@@ -420,7 +413,7 @@ - (instancetype)initWithAttributes:(NSDictionary *)textAttributes insets:(UIEdge
420413
_textInsets = textInsets;
421414
_textAttributes = [textAttributes copy];
422415
_textNode = [[ASTextNode alloc] init];
423-
[self addSubnode:_textNode];
416+
self.automaticallyManagesSubnodes = YES;
424417
}
425418
return self;
426419
}

AsyncDisplayKitTests/ASCollectionViewTests.mm

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,4 +1024,32 @@ - (void)testInitialRangeBounds
10241024
XCTAssertEqual([[cn valueForKeyPath:@"rangeController.currentRangeMode"] integerValue], ASLayoutRangeModeMinimum, @"Expected range mode to be minimum before scrolling begins.");
10251025
}
10261026

1027+
/**
1028+
* This tests an issue where, since subnode insertions aren't applied until the UIKit layout pass,
1029+
* which we trigger during the display phase, subnodes like network image nodes are not preloading
1030+
* until this layout pass happens which is too late.
1031+
*/
1032+
- (void)DISABLED_testThatAutomaticallyManagedSubnodesGetPreloadCallBeforeDisplay
1033+
{
1034+
UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
1035+
ASCollectionViewTestController *testController = [[ASCollectionViewTestController alloc] initWithNibName:nil bundle:nil];
1036+
window.rootViewController = testController;
1037+
ASCollectionNode *cn = testController.collectionNode;
1038+
1039+
__block NSInteger itemCount = 100;
1040+
testController.asyncDelegate->_itemCounts = {itemCount};
1041+
[window makeKeyAndVisible];
1042+
[window layoutIfNeeded];
1043+
1044+
[cn waitUntilAllUpdatesAreCommitted];
1045+
for (NSInteger i = 0; i < itemCount; i++) {
1046+
ASTextCellNodeWithSetSelectedCounter *node = [cn nodeForItemAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];
1047+
XCTAssert(node.automaticallyManagesSubnodes, @"Expected test cell node to use automatic subnode management. Can modify the test with a different class if needed.");
1048+
ASDisplayNode *subnode = node.textNode;
1049+
XCTAssertEqualObjects(NSStringFromASInterfaceState(subnode.interfaceState), NSStringFromASInterfaceState(node.interfaceState), @"Subtree interface state should match cell node interface state for ASM nodes.");
1050+
XCTAssert(node.inDisplayState || !node.nodeLoaded, @"Only nodes in the display range should be loaded.");
1051+
}
1052+
1053+
}
1054+
10271055
@end

0 commit comments

Comments
 (0)