Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 9357f54

Browse files
nguyenhuyHannah Troisi
authored andcommitted
Support visibility events in ASScrollNode (#2799)
* Support visibility events in ASScrollNode * Sort imports in ASScrollNode.mm
1 parent 3e53d26 commit 9357f54

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

AsyncDisplayKit/ASScrollNode.mm

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
//
1010

1111
#import "ASScrollNode.h"
12+
#import "ASDisplayNodeExtras.h"
13+
#import "ASDisplayNode+FrameworkPrivate.h"
1214
#import "ASDisplayNode+FrameworkSubclasses.h"
1315
#import "ASLayout.h"
1416
#import "_ASDisplayLayer.h"
@@ -24,6 +26,32 @@ + (Class)layerClass
2426
return [_ASDisplayLayer class];
2527
}
2628

29+
- (ASScrollNode *)scrollNode
30+
{
31+
return (ASScrollNode *)ASViewToDisplayNode(self);
32+
}
33+
34+
#pragma mark - _ASDisplayView behavior substitutions
35+
// Need these to drive interfaceState so we know when we are visible, if not nested in another range-managing element.
36+
// Because our superclass is a true UIKit class, we cannot also subclass _ASDisplayView.
37+
- (void)willMoveToWindow:(UIWindow *)newWindow
38+
{
39+
ASDisplayNode *node = self.scrollNode; // Create strong reference to weak ivar.
40+
BOOL visible = (newWindow != nil);
41+
if (visible && !node.inHierarchy) {
42+
[node __enterHierarchy];
43+
}
44+
}
45+
46+
- (void)didMoveToWindow
47+
{
48+
ASDisplayNode *node = self.scrollNode; // Create strong reference to weak ivar.
49+
BOOL visible = (self.window != nil);
50+
if (!visible && node.inHierarchy) {
51+
[node __exitHierarchy];
52+
}
53+
}
54+
2755
@end
2856

2957
@implementation ASScrollNode

0 commit comments

Comments
 (0)