Skip to content

Commit

Permalink
Add didEnterHierarchy/didExitHierarchy to ASNodeController. (TextureG…
Browse files Browse the repository at this point in the history
  • Loading branch information
tnorman42 authored and hebertialmeida committed May 10, 2019
1 parent 8dea604 commit 377aeeb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
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

0 comments on commit 377aeeb

Please sign in to comment.