From e82118e72f2d5b1246dede2873a3e2a3a474bf12 Mon Sep 17 00:00:00 2001 From: Michael Schneider Date: Wed, 16 Mar 2016 16:27:08 -0700 Subject: [PATCH] Add assertion for ASDisplayNode is layer backed if using ASInterfaceStateForDisplayNode --- AsyncDisplayKit/ASCollectionView.mm | 2 +- AsyncDisplayKit/ASDisplayNodeExtras.mm | 5 +++- AsyncDisplayKit/ASTableView.mm | 2 +- ...SRangeControllerUpdateRangeProtocol+Beta.h | 28 +++++++++---------- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/AsyncDisplayKit/ASCollectionView.mm b/AsyncDisplayKit/ASCollectionView.mm index 3ffa0ed180..fcf57e61ed 100644 --- a/AsyncDisplayKit/ASCollectionView.mm +++ b/AsyncDisplayKit/ASCollectionView.mm @@ -1137,7 +1137,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell"; [node __exitHierarchy]; } - // Updating the visible node index paths only for range managed nodes. Not range managed nodes will get their + // Updating the visible node index paths only for not range managed nodes. Range managed nodes will get their // their update in the layout pass if (![node supportsRangeManagedInterfaceState]) { [_rangeController visibleNodeIndexPathsDidChangeWithScrollDirection:self.scrollDirection]; diff --git a/AsyncDisplayKit/ASDisplayNodeExtras.mm b/AsyncDisplayKit/ASDisplayNodeExtras.mm index 20b055dcfd..95cb2a4e1f 100644 --- a/AsyncDisplayKit/ASDisplayNodeExtras.mm +++ b/AsyncDisplayKit/ASDisplayNodeExtras.mm @@ -12,8 +12,11 @@ extern ASInterfaceState ASInterfaceStateForDisplayNode(ASDisplayNode *displayNode, UIWindow *window) { + ASDisplayNodeCAssert(![displayNode isLayerBacked], @"displayNode must not be layer backed as it may have a nil window"); if (displayNode && [displayNode supportsRangeManagedInterfaceState]) { - // Only use the interfaceState of nodes that are range managed + // Directly clear the visible bit if we are not in a window. This means that the interface state is, + // if not already, about to be set to invisible as it is not possible for an element to be visible + // while outside of a window. ASInterfaceState interfaceState = displayNode.interfaceState; return (window == nil ? (interfaceState &= (~ASInterfaceStateVisible)) : interfaceState); } else { diff --git a/AsyncDisplayKit/ASTableView.mm b/AsyncDisplayKit/ASTableView.mm index 45b6010d43..a0d7374827 100644 --- a/AsyncDisplayKit/ASTableView.mm +++ b/AsyncDisplayKit/ASTableView.mm @@ -1069,7 +1069,7 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; [node __exitHierarchy]; } - // Updating the visible node index paths only for range managed nodes. Not range managed nodes will get their + // Updating the visible node index paths only for not range managed nodes. Range managed nodes will get their // their update in the layout pass if (![node supportsRangeManagedInterfaceState]) { [_rangeController visibleNodeIndexPathsDidChangeWithScrollDirection:self.scrollDirection]; diff --git a/AsyncDisplayKit/Details/ASRangeControllerUpdateRangeProtocol+Beta.h b/AsyncDisplayKit/Details/ASRangeControllerUpdateRangeProtocol+Beta.h index bf7e1dfbbe..3667a0a750 100644 --- a/AsyncDisplayKit/Details/ASRangeControllerUpdateRangeProtocol+Beta.h +++ b/AsyncDisplayKit/Details/ASRangeControllerUpdateRangeProtocol+Beta.h @@ -12,20 +12,6 @@ #import "ASCollectionNode.h" #import "ASTableNode.h" -/** - * Update the range mode for a range controller to a explicitly set range mode until the node that contains the range - * controller becomes visible again - * - * Logic for the automatic range mode: - * 1. If there are no visible node paths available nothing is to be done and no range update will happen - * 2. The initial range update if the range controller is visible always will be ASLayoutRangeModeCount - * (ASLayoutRangeModeMinimum) as it's the initial fetch - * 3. The range mode set explicitly via updateCurrentRangeWithMode: will last at least one range update. After that it - the range controller will use the explicit set range mode until it becomes visible and a new range update was - triggered or a new range mode via updateCurrentRangeWithMode: is set - * 4. If range mode is not explicitly set the range mode is variying based if the range controller is visible or not - */ - @protocol ASRangeControllerUpdateRangeProtocol @@ -48,7 +34,19 @@ @interface ASRangeController (ASRangeControllerUpdateRangeProtocol) -/// This is a way for a one way update of range with a given mode. +/** + * Update the range mode for a range controller to a explicitly set mode until the node that contains the range + * controller becomes visible again + * + * Logic for the automatic range mode: + * 1. If there are no visible node paths available nothing is to be done and no range update will happen + * 2. The initial range update if the range controller is visible always will be ASLayoutRangeModeCount + * (ASLayoutRangeModeMinimum) as it's the initial fetch + * 3. The range mode set explicitly via updateCurrentRangeWithMode: will last at least one range update. After that it + the range controller will use the explicit set range mode until it becomes visible and a new range update was + triggered or a new range mode via updateCurrentRangeWithMode: is set + * 4. If range mode is not explicitly set the range mode is variying based if the range controller is visible or not + */ - (void)updateCurrentRangeWithMode:(ASLayoutRangeMode)rangeMode; @end