Skip to content

Commit

Permalink
Restore call pattern where UIView methods drive __enterHierarchy and …
Browse files Browse the repository at this point in the history
…__exitHierarchy for view-backed nodes (#1561)

After #1396, some view-backed nodes in our app stop responding to tap events. I tracked it down to [this change](https://github.com/TextureGroup/Texture/pull/1396/files#diff-7fbc7d84a259cbfbee7546a5310dddcfR162) which suggests that the order of execution matters.

This diff attempts to fix the issue by restoring the previous call order where `__enterHierarchy` and `__exitHierarchy` are driven by `_ASDisplayView`'s `-willMoveToWindow:` and `-didMoveToWindow` if the node is view-backed. Layer-backed nodes will still call `__enterHierarchy`/`__exitHierarchy` when they get `kCAOnOrderIn`/`kCAOnOrderOut`.

This maintains the layer-action support introduced in #1396.
  • Loading branch information
nguyenhuy authored and Adlai-Holler committed Jun 25, 2019
1 parent 533c7eb commit ba1e0ac
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1722,10 +1722,14 @@ - (void)subnodeDisplayDidFinish:(ASDisplayNode *)subnode

- (id<CAAction>)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];
Expand Down
18 changes: 18 additions & 0 deletions Source/Details/_ASDisplayView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ba1e0ac

Please sign in to comment.