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

Add didEnterHierarchy/didExitHierarchy to ASNodeController. #1444

Merged
merged 1 commit into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Source/ASDisplayNode+InterfaceState.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,22 @@ typedef NS_OPTIONS(NSUInteger, ASInterfaceState)
*/
- (void)nodeWillCalculateLayout:(ASSizeRange)constrainedSize;

/**
* @abstract Called when the node's layer is about to enter the hierarchy.
* @discussion May be called more than once if the layer is participating in a higher-level
* animation, such as a UIViewController transition. These animations can cause the layer to get
* re-parented multiple times, and each time will trigger this call.
* @note This method is guaranteed to be called on main.
*/
- (void)didEnterHierarchy;

/**
* @abstract Called when the node's layer has exited the hierarchy.
* @discussion May be called more than once if the layer is participating in a higher-level
* animation, such as a UIViewController transition. These animations can cause the layer to get
* re-parented multiple times, and each time will trigger this call.
* @note This method is guaranteed to be called on main.
*/
- (void)didExitHierarchy;

@end
12 changes: 12 additions & 0 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2874,6 +2874,12 @@ - (void)didEnterHierarchy {
ASDisplayNodeAssert(!_flags.isExitingHierarchy, @"ASDisplayNode inconsistency. __enterHierarchy and __exitHierarchy are mutually exclusive");
ASDisplayNodeAssert(_flags.isInHierarchy, @"ASDisplayNode inconsistency. __enterHierarchy and __exitHierarchy are mutually exclusive");
ASAssertUnlocked(__instanceLock__);

[self enumerateInterfaceStateDelegates:^(id<ASInterfaceStateDelegate> del) {
if ([del respondsToSelector:@selector(didEnterHierarchy)]) {
[del didEnterHierarchy];
}
}];
}

- (void)didExitHierarchy
Expand All @@ -2883,6 +2889,12 @@ - (void)didExitHierarchy
ASDisplayNodeAssert(!_flags.isEnteringHierarchy, @"ASDisplayNode inconsistency. __enterHierarchy and __exitHierarchy are mutually exclusive");
ASAssertUnlocked(__instanceLock__);

[self enumerateInterfaceStateDelegates:^(id<ASInterfaceStateDelegate> del) {
if ([del respondsToSelector:@selector(didExitHierarchy)]) {
[del didExitHierarchy];
}
}];

// This case is important when tearing down hierarchies. We must deliver a visibileStateDidChange:NO callback, as part our API guarantee that this method can be used for
// things like data analytics about user content viewing. We cannot call the method in the dealloc as any incidental retain operations in client code would fail.
// Additionally, it may be that a Standard UIView which is containing us is moving between hierarchies, and we should not send the call if we will be re-added in the
Expand Down
3 changes: 3 additions & 0 deletions Source/ASNodeController+Beta.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@

- (void)hierarchyDisplayDidFinish ASDISPLAYNODE_REQUIRES_SUPER;

- (void)didEnterHierarchy ASDISPLAYNODE_REQUIRES_SUPER;
- (void)didExitHierarchy ASDISPLAYNODE_REQUIRES_SUPER;

/**
* @discussion Attempts (via ASLockSequence, a backing-off spinlock similar to
* std::lock()) to lock both the node and its ASNodeController, if one exists.
Expand Down
3 changes: 3 additions & 0 deletions Source/ASNodeController+Beta.mm
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ - (void)interfaceStateDidChange:(ASInterfaceState)newState

- (void)hierarchyDisplayDidFinish {}

- (void)didEnterHierarchy {}
- (void)didExitHierarchy {}

- (ASLockSet)lockPair {
ASLockSet lockSet = ASLockSequence(^BOOL(ASAddLockBlock addLock) {
if (!addLock(_node)) {
Expand Down