1212#import " ASDisplayNode+Subclasses.h"
1313#import " ASDisplayNodeInternal.h"
1414
15+ @interface ASRangeHandlerRender ()
16+ @property (nonatomic ,readonly ) UIWindow *workingWindow;
17+ @end
18+
1519@implementation ASRangeHandlerRender
20+ @synthesize workingWindow = _workingWindow;
1621
17- + (UIWindow *)workingWindow
22+ - (UIWindow *)workingWindow
1823{
1924 ASDisplayNodeAssertMainThread ();
20-
25+
2126 // we add nodes' views to this invisible window to start async rendering
2227 // TODO: Replace this with directly triggering display https://github.com/facebook/AsyncDisplayKit/issues/315
23- static UIWindow *workingWindow = nil ;
24- static dispatch_once_t onceToken;
25- dispatch_once (&onceToken, ^{
26- workingWindow = [[UIWindow alloc ] initWithFrame: CGRectZero];
27- workingWindow.windowLevel = UIWindowLevelNormal - 1000 ;
28- workingWindow.userInteractionEnabled = NO ;
29- workingWindow.hidden = YES ;
30- workingWindow.alpha = 0.0 ;
31- });
32- return workingWindow;
28+ // Update: Latest attempt is at https://github.com/facebook/AsyncDisplayKit/pull/828
29+
30+ if (!_workingWindow) {
31+ _workingWindow = [[UIWindow alloc ] initWithFrame: CGRectZero];
32+ _workingWindow.windowLevel = UIWindowLevelNormal - 1000 ;
33+ _workingWindow.userInteractionEnabled = NO ;
34+ _workingWindow.hidden = YES ;
35+ _workingWindow.alpha = 0.0 ;
36+ }
37+
38+ return _workingWindow;
39+ }
40+
41+ - (void )dealloc
42+ {
43+ for (CALayer *layer in self.workingWindow .layer .sublayers ) {
44+ ASDisplayNode *node = layer.asyncdisplaykit_node ;
45+ [self node: node exitedRangeOfType: ASLayoutRangeTypeRender];
46+ }
3347}
3448
3549- (void )node : (ASDisplayNode *)node enteredRangeOfType : (ASLayoutRangeType)rangeType
@@ -50,7 +64,7 @@ - (void)node:(ASDisplayNode *)node enteredRangeOfType:(ASLayoutRangeType)rangeTy
5064 // Any view-backed nodes will still create their views in order to assemble the layer heirarchy, and they will
5165 // also assemble a view subtree for the node, but we avoid the much more significant expense triggered by a view
5266 // being added or removed from an onscreen window (responder chain setup, will/DidMoveToWindow: recursive calls, etc)
53- [[[[ self class ] workingWindow ] layer ] addSublayer: node.layer];
67+ [[[self workingWindow ] layer ] addSublayer: node.layer];
5468}
5569
5670- (void )node : (ASDisplayNode *)node exitedRangeOfType : (ASLayoutRangeType)rangeType
@@ -77,7 +91,7 @@ - (void)node:(ASDisplayNode *)node exitedRangeOfType:(ASLayoutRangeType)rangeTyp
7791
7892 [node recursivelySetDisplaySuspended: YES ];
7993
80- if (node.layer .superlayer != [[[ self class ] workingWindow ] layer ]) {
94+ if (node.layer .superlayer != [[self workingWindow ] layer ]) {
8195 // In this case, the node has previously passed through the working range (or it is zero), and it has now fallen outside the working range.
8296 if (![node isLayerBacked ]) {
8397 // If the node is view-backed, we need to make sure to remove the view (which is now present in the containing cell contentsView).
0 commit comments