From 36cbea4f8f534d2f7b0cdbddd681e14b1b9ddc3a Mon Sep 17 00:00:00 2001 From: Ryan Nystrom Date: Thu, 4 Dec 2014 10:12:52 -0800 Subject: [PATCH] Update manual display logic Postpone manual display until a future release when it can be called on any thread. Provide the current node manual display logic as a category on ASDisplayNode only available for ASRangeController. Deprecate -displayImmediately. --- AsyncDisplayKit/ASDisplayNode.h | 18 --------- AsyncDisplayKit/ASDisplayNode.mm | 27 ------------- AsyncDisplayKit/Details/ASRangeController.mm | 39 +++++++++++++++++++ .../Private/ASDisplayNodeInternal.h | 3 ++ 4 files changed, 42 insertions(+), 45 deletions(-) diff --git a/AsyncDisplayKit/ASDisplayNode.h b/AsyncDisplayKit/ASDisplayNode.h index 8af6efba80..bf72daf2be 100644 --- a/AsyncDisplayKit/ASDisplayNode.h +++ b/AsyncDisplayKit/ASDisplayNode.h @@ -294,24 +294,6 @@ */ @property (nonatomic, assign) BOOL shouldRasterizeDescendants; -/** - * @abstract Calls -setNeedsDisplay and -displayIfNeeded on the node's backing store. - * - * @note This method must be called on the main thread but there are plans to allow this on any thread. - */ -- (void)display; - -/** - * @abstract Call -display on the node and recursively on all subnodes, forcing the entire node hierarchy to be - * displayed. - */ -- (void)recursivelyDisplay; - -/** - * @abstract Display the node's view/layer immediately on the current thread, bypassing the background thread rendering. - */ -- (void)displayImmediately; - /** * @abstract Prevent the node's layer from displaying. * diff --git a/AsyncDisplayKit/ASDisplayNode.mm b/AsyncDisplayKit/ASDisplayNode.mm index d9a8305394..a308708d53 100644 --- a/AsyncDisplayKit/ASDisplayNode.mm +++ b/AsyncDisplayKit/ASDisplayNode.mm @@ -434,33 +434,6 @@ void ASDisplayNodePerformBlockOnMainThread(void (^block)()) _contentsScaleForDisplay = contentsScaleForDisplay; } -- (void)display -{ - ASDisplayNodeAssertMainThread(); - ASDisplayNodeAssert(self.nodeLoaded, @"backing store must be loaded before calling -display"); - - // rendering a backing store requires a node be laid out - [self __layout]; - - CALayer *layer = [self isLayerBacked] ? self.layer : self.view.layer; - - if (layer.contents) { - return; - } - - [layer setNeedsDisplay]; - [layer displayIfNeeded]; -} - -- (void)recursivelyDisplay -{ - for (ASDisplayNode *node in self.subnodes) { - [node recursivelyDisplay]; - } - - [self display]; -} - - (void)displayImmediately { ASDisplayNodeAssertMainThread(); diff --git a/AsyncDisplayKit/Details/ASRangeController.mm b/AsyncDisplayKit/Details/ASRangeController.mm index 64bc6ccd5c..2f50f4499f 100644 --- a/AsyncDisplayKit/Details/ASRangeController.mm +++ b/AsyncDisplayKit/Details/ASRangeController.mm @@ -13,6 +13,45 @@ #import "ASDisplayNodeInternal.h" #import "ASRangeControllerInternal.h" +@interface ASDisplayNode (ASRangeController) + +- (void)display; +- (void)recursivelyDisplay; + +@end + +@implementation ASDisplayNode (ASRangeController) + +- (void)display +{ + ASDisplayNodeAssertMainThread(); + ASDisplayNodeAssert(self.nodeLoaded, @"backing store must be loaded before calling -display"); + + CALayer *layer = self.layer; + + // rendering a backing store requires a node be laid out + [layer setNeedsLayout]; + [layer layoutIfNeeded]; + + if (layer.contents) { + return; + } + + [layer setNeedsDisplay]; + [layer displayIfNeeded]; +} + +- (void)recursivelyDisplay +{ + for (ASDisplayNode *node in self.subnodes) { + [node recursivelyDisplay]; + } + + [self display]; +} + +@end + @interface ASRangeController () { // index path -> node mapping NSMutableDictionary *_nodes; diff --git a/AsyncDisplayKit/Private/ASDisplayNodeInternal.h b/AsyncDisplayKit/Private/ASDisplayNodeInternal.h index 15d4258ea8..7081b0c07d 100644 --- a/AsyncDisplayKit/Private/ASDisplayNodeInternal.h +++ b/AsyncDisplayKit/Private/ASDisplayNodeInternal.h @@ -115,6 +115,9 @@ void ASDisplayNodePerformBlockOnMainThread(void (^block)()); // Call didExitHierarchy if necessary and set inHierarchy = NO if visibility notifications are enabled on all of its parents - (void)__exitHierarchy; +// Display the node's view/layer immediately on the current thread, bypassing the background thread rendering. Will be deprecated. +- (void)displayImmediately; + // Returns the ancestor node that rasterizes descendants, or nil if none. - (ASDisplayNode *)__rasterizedContainerNode;