diff --git a/Source/ASDisplayNode.mm b/Source/ASDisplayNode.mm index f781f9c6b..980be8f0c 100644 --- a/Source/ASDisplayNode.mm +++ b/Source/ASDisplayNode.mm @@ -1722,10 +1722,14 @@ - (void)subnodeDisplayDidFinish:(ASDisplayNode *)subnode - (id)actionForLayer:(CALayer *)layer forKey:(NSString *)event { - if (event == kCAOnOrderIn) { - [self __enterHierarchy]; - } else if (event == kCAOnOrderOut) { - [self __exitHierarchy]; + // Only drive __enterHierarchy and __exitHierarchy if the node is layer-backed. + // View-backed nodes handle them in _ASDisplayView's -willMoveToWindow: and -didMoveToWindow. + if (self.isLayerBacked) { + if (event == kCAOnOrderIn) { + [self __enterHierarchy]; + } else if (event == kCAOnOrderOut) { + [self __exitHierarchy]; + } } return [self layerActionForKey:event]; diff --git a/Source/Details/_ASDisplayView.mm b/Source/Details/_ASDisplayView.mm index 9ba6176f4..7509a704e 100644 --- a/Source/Details/_ASDisplayView.mm +++ b/Source/Details/_ASDisplayView.mm @@ -99,6 +99,24 @@ - (NSString *)description return nodeAction; } +- (void)willMoveToWindow:(UIWindow *)newWindow +{ + ASDisplayNode *node = _asyncdisplaykit_node; // Create strong reference to weak ivar. + BOOL visible = (newWindow != nil); + if (visible && !node.inHierarchy) { + [node __enterHierarchy]; + } +} + +- (void)didMoveToWindow +{ + ASDisplayNode *node = _asyncdisplaykit_node; // Create strong reference to weak ivar. + BOOL visible = (self.window != nil); + if (!visible && node.inHierarchy) { + [node __exitHierarchy]; + } +} + - (void)willMoveToSuperview:(UIView *)newSuperview { // Keep the node alive while the view is in a view hierarchy. This helps ensure that async-drawing views can always