Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Ancestry Handling, Avoid Assertion Failure #246

Merged
merged 3 commits into from
May 10, 2017

Conversation

Adlai-Holler
Copy link
Member

@Adlai-Holler Adlai-Holler commented May 5, 2017

This is a more complete fix for #240 and supersedes #241 .

  • The assertion failure is only due to loading the layer during upward traversal, which we shouldn't do. This diff prevents that from happening.
  • Add public category methods supernodes supernodesIncludingSelf and supernodeOfClass:includingSelf:.
    • I thought about these names a lot. The word ancestry is more precise but I think these names are more user-friendly.
  • Deprecate ASDisplayNodeFindFirstSupernode() and ASDisplayNodeFindFirstSupernodeOfClass() in favor of the new category methods.
  • Remove a redundant/silly code path in ASDisplayNode.layer that checks self.view.layer. No! We either have _layer or we need to load it, end of story.
  • Renames -_locked_loadViewOrLayerIsLayerBacked: to simply -_locked_loadViewOrLayer. We can just check the flag ourselves inside the method.

if (block(node)) {
return node;
// This function has historically started with `self` but the name suggests
// that it wouldn't. Perhaps we should change the behavior.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're deprecating it, shouldn't we leave it as is?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I think you're keeping the behavior but the comment is incorrect? Same with below?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep we're keeping it the same.

@@ -125,12 +125,12 @@ extern void ASDisplayNodePerformBlockOnEverySubnode(ASDisplayNode *node, BOOL tr
/**
Given a display node, traverses up the layer tree hierarchy, returning the first display node that passes block.
*/
extern ASDisplayNode * _Nullable ASDisplayNodeFindFirstSupernode(ASDisplayNode * _Nullable node, BOOL (^block)(ASDisplayNode *node)) AS_WARN_UNUSED_RESULT;
extern ASDisplayNode * _Nullable ASDisplayNodeFindFirstSupernode(ASDisplayNode * _Nullable node, BOOL (^block)(ASDisplayNode *node)) AS_WARN_UNUSED_RESULT ASDISPLAYNODE_DEPRECATED_MSG("Use the `supernodes` property instead.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the msg also mention supernodesIncludingSelf?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh it's a matter of taste but I don't think so – they'll see it when they search around, and these messages are better when they're shorter.

* }
* }
*
* Note: If this property is read on the main thread, the enumeration will attempt to go up
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the above example code dangerous then? It's casting to an ASDisplayNode when it could be either a node or a layer? I don't think the above would crash but it's a little misleading.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the very least the note should be an @warning

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frankly this behavior actually seems pretty crazy, are we sure we want to expose this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No these are always going to be nodes. We are just traversing the layer hierarchy to find more nodes when there's a break. Same behavior that we use when traversing subnodes in ASPerformBlockOnEveryNode.

Copy link
Member

@appleguy appleguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great improvement, because it allows us to inspect as much of the hierarchy is safe to explore at any given time.

There is still one small issue for #240 remaining, but it is orthogonal to this one -- accessing self.alpha of a loaded node when printing any description on a background thread. Look at the -description method in ASDisplayNode.

@Adlai-Holler
Copy link
Member Author

Adlai-Holler commented May 9, 2017

Hey great a CHANGELOG conflict I can't wait to not be able to merge this until the CI runs again. 😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants