Skip to content

Commit 981482c

Browse files
tnorman42Adlai-Holler
authored andcommitted
Add didEnterHierarchy/didExitHierarchy to ASNodeController. (facebookarchive#1444)
1 parent d55fd47 commit 981482c

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

Source/ASDisplayNode+InterfaceState.h

+18
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,22 @@ typedef NS_OPTIONS(NSUInteger, ASInterfaceState)
127127
*/
128128
- (void)nodeWillCalculateLayout:(ASSizeRange)constrainedSize;
129129

130+
/**
131+
* @abstract Called when the node's layer is about to enter the hierarchy.
132+
* @discussion May be called more than once if the layer is participating in a higher-level
133+
* animation, such as a UIViewController transition. These animations can cause the layer to get
134+
* re-parented multiple times, and each time will trigger this call.
135+
* @note This method is guaranteed to be called on main.
136+
*/
137+
- (void)didEnterHierarchy;
138+
139+
/**
140+
* @abstract Called when the node's layer has exited the hierarchy.
141+
* @discussion May be called more than once if the layer is participating in a higher-level
142+
* animation, such as a UIViewController transition. These animations can cause the layer to get
143+
* re-parented multiple times, and each time will trigger this call.
144+
* @note This method is guaranteed to be called on main.
145+
*/
146+
- (void)didExitHierarchy;
147+
130148
@end

Source/ASDisplayNode.mm

+12
Original file line numberDiff line numberDiff line change
@@ -2874,6 +2874,12 @@ - (void)didEnterHierarchy {
28742874
ASDisplayNodeAssert(!_flags.isExitingHierarchy, @"ASDisplayNode inconsistency. __enterHierarchy and __exitHierarchy are mutually exclusive");
28752875
ASDisplayNodeAssert(_flags.isInHierarchy, @"ASDisplayNode inconsistency. __enterHierarchy and __exitHierarchy are mutually exclusive");
28762876
ASAssertUnlocked(__instanceLock__);
2877+
2878+
[self enumerateInterfaceStateDelegates:^(id<ASInterfaceStateDelegate> del) {
2879+
if ([del respondsToSelector:@selector(didEnterHierarchy)]) {
2880+
[del didEnterHierarchy];
2881+
}
2882+
}];
28772883
}
28782884

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

2892+
[self enumerateInterfaceStateDelegates:^(id<ASInterfaceStateDelegate> del) {
2893+
if ([del respondsToSelector:@selector(didExitHierarchy)]) {
2894+
[del didExitHierarchy];
2895+
}
2896+
}];
2897+
28862898
// 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
28872899
// 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.
28882900
// 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

Source/ASNodeController+Beta.h

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444

4545
- (void)hierarchyDisplayDidFinish ASDISPLAYNODE_REQUIRES_SUPER;
4646

47+
- (void)didEnterHierarchy ASDISPLAYNODE_REQUIRES_SUPER;
48+
- (void)didExitHierarchy ASDISPLAYNODE_REQUIRES_SUPER;
49+
4750
/**
4851
* @discussion Attempts (via ASLockSequence, a backing-off spinlock similar to
4952
* std::lock()) to lock both the node and its ASNodeController, if one exists.

Source/ASNodeController+Beta.mm

+3
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ - (void)interfaceStateDidChange:(ASInterfaceState)newState
9292

9393
- (void)hierarchyDisplayDidFinish {}
9494

95+
- (void)didEnterHierarchy {}
96+
- (void)didExitHierarchy {}
97+
9598
- (ASLockSet)lockPair {
9699
ASLockSet lockSet = ASLockSequence(^BOOL(ASAddLockBlock addLock) {
97100
if (!addLock(_node)) {

0 commit comments

Comments
 (0)