From 904905189c9959e54796cbc7a2b3850bbe1b2b00 Mon Sep 17 00:00:00 2001 From: Scott Goodson Date: Sat, 20 Jun 2015 19:40:01 -0700 Subject: [PATCH] Remove -[_ASDisplayView layoutSubviews] and use only -[_ASDisplayLayer layoutSublayers]. This helps us support special cases such as ASScrollNode correctly driving the -layout method for subclasses even though it is based on UIScrollView & can't use _ASDisplayView. I suspect this will be useful for ASCollectionNode and ASTableNode as well, which would allow nesting those classes inside of other collections / tables (e.g. horizontal unit within a vertical unit). --- AsyncDisplayKit/ASScrollNode.m | 15 ++++++++++++++- AsyncDisplayKit/Details/_ASDisplayLayer.mm | 9 ++++++--- AsyncDisplayKit/Details/_ASDisplayView.mm | 13 ------------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/AsyncDisplayKit/ASScrollNode.m b/AsyncDisplayKit/ASScrollNode.m index 3b19d126e2..ade0ee9e5e 100644 --- a/AsyncDisplayKit/ASScrollNode.m +++ b/AsyncDisplayKit/ASScrollNode.m @@ -7,6 +7,19 @@ */ #import "ASScrollNode.h" +#import "_ASDisplayLayer.h" + +@interface ASScrollView : UIScrollView +@end + +@implementation ASScrollView + ++ (Class)layerClass +{ + return [_ASDisplayLayer class]; +} + +@end @implementation ASScrollNode @dynamic view; @@ -14,7 +27,7 @@ - (instancetype)init { return [super initWithViewBlock:^UIView *{ - return [[UIScrollView alloc] init]; + return [[ASScrollView alloc] init]; }]; } diff --git a/AsyncDisplayKit/Details/_ASDisplayLayer.mm b/AsyncDisplayKit/Details/_ASDisplayLayer.mm index 9240c0a42a..1acee3bd58 100644 --- a/AsyncDisplayKit/Details/_ASDisplayLayer.mm +++ b/AsyncDisplayKit/Details/_ASDisplayLayer.mm @@ -93,10 +93,13 @@ [super layoutSublayers]; ASDisplayNode *node = self.asyncdisplaykit_node; - // If our associated node is layer-backed, we cannot rely on the view's -layoutSubviews calling the node's -layout implementation, so do it ourselves. - if (node.isLayerBacked) { - ASDisplayNodeAssertMainThread(); + if (ASDisplayNodeThreadIsMain()) { [node __layout]; + } else { + ASDisplayNodeFailAssert(@"not reached assertion"); + dispatch_async(dispatch_get_main_queue(), ^ { + [node __layout]; + }); } } diff --git a/AsyncDisplayKit/Details/_ASDisplayView.mm b/AsyncDisplayKit/Details/_ASDisplayView.mm index 8a71013fbe..1bebdb9815 100644 --- a/AsyncDisplayKit/Details/_ASDisplayView.mm +++ b/AsyncDisplayKit/Details/_ASDisplayView.mm @@ -122,19 +122,6 @@ } } -- (void)layoutSubviews -{ - if (ASDisplayNodeThreadIsMain()) { - [_node __layout]; - } else { - // FIXME: CRASH This should not be happening because of the way we gate -setNeedsLayout, but it has been seen. - ASDisplayNodeFailAssert(@"not reached assertion"); - dispatch_async(dispatch_get_main_queue(), ^ { - [_node __layout]; - }); - } -} - - (UIViewContentMode)contentMode { return ASDisplayNodeUIContentModeFromCAContentsGravity(self.layer.contentsGravity);