diff --git a/AsyncDisplayKit/ASCollectionView.mm b/AsyncDisplayKit/ASCollectionView.mm index e535728834..3ffa0ed180 100644 --- a/AsyncDisplayKit/ASCollectionView.mm +++ b/AsyncDisplayKit/ASCollectionView.mm @@ -917,17 +917,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell"; - (ASInterfaceState)interfaceStateForRangeController:(ASRangeController *)rangeController { - ASCollectionNode *collectionNode = self.collectionNode; - if (collectionNode && [collectionNode supportsRangeManagedInterfaceState]) { - // Only use the interfaceState of nodes that are range managed - ASInterfaceState interfaceState = collectionNode.interfaceState; - return (self.window == nil ? (interfaceState &= (~ASInterfaceStateVisible)) : interfaceState); - } else { - // For not range managed nodes or until we can always create an associated ASCollectionNode - // without a retain cycle, we might be on our own to try to guess if we're visible. The node normally - // handles this even if it is the root / directly added to the view hierarchy. - return (self.window == nil ? ASInterfaceStateNone : (ASInterfaceStateVisible | ASInterfaceStateDisplay)); - } + return ASInterfaceStateForDisplayNode(self.collectionNode, self.window); } - (NSArray *)rangeController:(ASRangeController *)rangeController nodesAtIndexPaths:(NSArray *)indexPaths diff --git a/AsyncDisplayKit/ASDisplayNodeExtras.h b/AsyncDisplayKit/ASDisplayNodeExtras.h index 6b5bf3f84d..e555bf83c3 100644 --- a/AsyncDisplayKit/ASDisplayNodeExtras.h +++ b/AsyncDisplayKit/ASDisplayNodeExtras.h @@ -59,6 +59,11 @@ NS_ASSUME_NONNULL_BEGIN ASDISPLAYNODE_EXTERN_C_BEGIN +/** + Returns the appropriate interface state for a given ASDisplayNode and window + */ +extern ASInterfaceState ASInterfaceStateForDisplayNode(ASDisplayNode *displayNode, UIWindow *window); + /** Given a layer, returns the associated display node, if any. */ diff --git a/AsyncDisplayKit/ASDisplayNodeExtras.mm b/AsyncDisplayKit/ASDisplayNodeExtras.mm index 75b9ddd575..20b055dcfd 100644 --- a/AsyncDisplayKit/ASDisplayNodeExtras.mm +++ b/AsyncDisplayKit/ASDisplayNodeExtras.mm @@ -10,6 +10,18 @@ #import "ASDisplayNodeInternal.h" #import "ASDisplayNode+FrameworkPrivate.h" +extern ASInterfaceState ASInterfaceStateForDisplayNode(ASDisplayNode *displayNode, UIWindow *window) +{ + if (displayNode && [displayNode supportsRangeManagedInterfaceState]) { + // Only use the interfaceState of nodes that are range managed + ASInterfaceState interfaceState = displayNode.interfaceState; + return (window == nil ? (interfaceState &= (~ASInterfaceStateVisible)) : interfaceState); + } else { + // For not range managed nodes we might be on our own to try to guess if we're visible. + return (window == nil ? ASInterfaceStateNone : (ASInterfaceStateVisible | ASInterfaceStateDisplay)); + } +} + extern ASDisplayNode *ASLayerToDisplayNode(CALayer *layer) { return layer.asyncdisplaykit_node; diff --git a/AsyncDisplayKit/ASTableView.mm b/AsyncDisplayKit/ASTableView.mm index 734a867e79..45b6010d43 100644 --- a/AsyncDisplayKit/ASTableView.mm +++ b/AsyncDisplayKit/ASTableView.mm @@ -794,17 +794,7 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; - (ASInterfaceState)interfaceStateForRangeController:(ASRangeController *)rangeController { - ASTableNode *tableNode = self.tableNode; - if (tableNode && [tableNode supportsRangeManagedInterfaceState]) { - // Only use the interfaceState of nodes that are range managed - ASInterfaceState interfaceState = self.tableNode.interfaceState; - return (self.window == nil ? (interfaceState &= (~ASInterfaceStateVisible)) : interfaceState); - } else { - // For not range managed nodes or until we can always create an associated ASTableNode - // without a retain cycle, we might be on our own to try to guess if we're visible. The node normally - // handles this even if it is the root / directly added to the view hierarchy. - return (self.window == nil ? ASInterfaceStateNone : (ASInterfaceStateVisible | ASInterfaceStateDisplay)); - } + return ASInterfaceStateForDisplayNode(self.tableNode, self.window); } #pragma mark - ASRangeControllerDelegate