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

Commit

Permalink
Prevent Adding View-Backed Nodes to Layer-Backed Hierarchies (#3062)
Browse files Browse the repository at this point in the history
* Prevent adding view-backed nodes to layer-backed nodes

* Do that in a different diff

* Fix the message

* Update tests

* Fix the fix
  • Loading branch information
Adlai Holler authored Feb 23, 2017
1 parent 86dd918 commit 6ab92db
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
7 changes: 6 additions & 1 deletion AsyncDisplayKit/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2551,6 +2551,11 @@ - (void)_insertSubnode:(ASDisplayNode *)subnode atSubnodeIndex:(NSInteger)subnod
return;
}

if (self.layerBacked && !subnode.layerBacked) {
ASDisplayNodeFailAssert(@"Cannot add a view-backed node as a subnode of a layer-backed node. Supernode: %@, subnode: %@", self, subnode);
return;
}

__instanceLock__.lock();
NSUInteger subnodesCount = _subnodes.count;
__instanceLock__.unlock();
Expand Down Expand Up @@ -3177,7 +3182,7 @@ - (void)setHierarchyState:(ASHierarchyState)newState
ASDisplayNodeAssert(_flags.synchronous == NO, @"Node created using -initWithViewBlock:/-initWithLayerBlock: cannot be added to subtree of node with shouldRasterizeDescendants=YES. Node: %@", self);
}

// Entered or exited contents rendering state.
// Entered or exited range managed state.
if ((newState & ASHierarchyStateRangeManaged) != (oldState & ASHierarchyStateRangeManaged)) {
if (newState & ASHierarchyStateRangeManaged) {
[self enterInterfaceState:self.supernode.interfaceState];
Expand Down
14 changes: 7 additions & 7 deletions AsyncDisplayKitTests/ASDisplayNodeTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1098,33 +1098,34 @@ - (void)testSubnodes

- (void)testReplaceSubnodeNoView
{
[self checkReplaceSubnodeWithView:NO layerBacked:NO];
[self checkReplaceSubnodeLoaded:NO layerBacked:NO];
}

- (void)testReplaceSubnodeNoLayer
{
[self checkReplaceSubnodeWithView:NO layerBacked:YES];
[self checkReplaceSubnodeLoaded:NO layerBacked:YES];
}

- (void)testReplaceSubnodeView
{
[self checkReplaceSubnodeWithView:YES layerBacked:NO];
[self checkReplaceSubnodeLoaded:YES layerBacked:NO];
}

- (void)testReplaceSubnodeLayer
{
[self checkReplaceSubnodeWithView:YES layerBacked:YES];
[self checkReplaceSubnodeLoaded:YES layerBacked:YES];
}


- (void)checkReplaceSubnodeWithView:(BOOL)loaded layerBacked:(BOOL)isLayerBacked
- (void)checkReplaceSubnodeLoaded:(BOOL)loaded layerBacked:(BOOL)isLayerBacked
{
DeclareNodeNamed(parent);
DeclareNodeNamed(a);
DeclareNodeNamed(b);
DeclareNodeNamed(c);
DeclareNodeNamed(d);

for (ASDisplayNode *n in @[parent, a, b, c]) {
for (ASDisplayNode *n in @[parent, a, b, c, d]) {
n.layerBacked = isLayerBacked;
}

Expand All @@ -1136,7 +1137,6 @@ - (void)checkReplaceSubnodeWithView:(BOOL)loaded layerBacked:(BOOL)isLayerBacked
[parent layer];
}

DeclareNodeNamed(d);
if (loaded) {
XCTAssertFalse(d.nodeLoaded, @"Should not yet be loaded");
}
Expand Down
1 change: 1 addition & 0 deletions examples/ASDKgram/Sample/CommentsNode.m
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ - (void)createCommentLabels
for (NSUInteger i = 0; i < numLabelsToAdd; i++) {

ASTextNode *commentLabel = [[ASTextNode alloc] init];
commentLabel.layerBacked = YES;
commentLabel.maximumNumberOfLines = 3;

[_commentNodes addObject:commentLabel];
Expand Down

0 comments on commit 6ab92db

Please sign in to comment.