From ea777456b61efdf39966bab5bf5061c9351da16a Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Thu, 21 Apr 2016 14:41:01 -0500 Subject: [PATCH 1/2] [ASCellNode] Apply layout delegate behavior in -__setNeedsLayout, not -setNeedsLayout --- AsyncDisplayKit/ASCellNode.h | 15 ++++----------- AsyncDisplayKit/{ASCellNode.m => ASCellNode.mm} | 5 +++-- 2 files changed, 7 insertions(+), 13 deletions(-) rename AsyncDisplayKit/{ASCellNode.m => ASCellNode.mm} (99%) diff --git a/AsyncDisplayKit/ASCellNode.h b/AsyncDisplayKit/ASCellNode.h index e38376bee4..93de119cb8 100644 --- a/AsyncDisplayKit/ASCellNode.h +++ b/AsyncDisplayKit/ASCellNode.h @@ -34,6 +34,10 @@ typedef NS_ENUM(NSUInteger, ASCellNodeVisibilityEvent) { /** * Generic cell node. Subclass this instead of `ASDisplayNode` to use with `ASTableView` and `ASCollectionView`. + + * @note When a cell node is contained inside a collection view (or table view), + * calling `-setNeedsLayout` will also notify the collection on the main thread + * so that the collection can update its item layout if the cell's size changed. */ @interface ASCellNode : ASDisplayNode @@ -85,17 +89,6 @@ typedef NS_ENUM(NSUInteger, ASCellNodeVisibilityEvent) { - (void)touchesEnded:(NSSet *)touches withEvent:(nullable UIEvent *)event ASDISPLAYNODE_REQUIRES_SUPER; - (void)touchesCancelled:(nullable NSSet *)touches withEvent:(nullable UIEvent *)event ASDISPLAYNODE_REQUIRES_SUPER; -/** - * Marks the node as needing layout. Convenience for use whether the view / layer is loaded or not. - * - * If this node was measured, calling this method triggers an internal relayout: the calculated layout is invalidated, - * and the supernode is notified or (if this node is the root one) a full measurement pass is executed using the old constrained size. - * The delegate will then be notified on main thread. - * - * This method can be called inside of an animation block (to animate all of the layout changes). - */ -- (void)setNeedsLayout; - /** * @abstract Initializes a cell with a given view controller block. * diff --git a/AsyncDisplayKit/ASCellNode.m b/AsyncDisplayKit/ASCellNode.mm similarity index 99% rename from AsyncDisplayKit/ASCellNode.m rename to AsyncDisplayKit/ASCellNode.mm index b83c569226..b1971fafe6 100644 --- a/AsyncDisplayKit/ASCellNode.m +++ b/AsyncDisplayKit/ASCellNode.mm @@ -10,6 +10,7 @@ #import "ASInternalHelpers.h" #import "ASEqualityHelpers.h" +#import "ASDisplayNodeInternal.h" #import #import #import @@ -120,10 +121,10 @@ ASDisplayNodeAssert(!layerBacked, @"ASCellNode does not support layer-backing."); } -- (void)setNeedsLayout +- (void)__setNeedsLayout { CGSize oldSize = self.calculatedSize; - [super setNeedsLayout]; + [super __setNeedsLayout]; [self didRelayoutFromOldSize:oldSize toNewSize:self.calculatedSize]; } From f66d109928225fe26aac5967ae3cabb593940a29 Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Thu, 21 Apr 2016 17:39:19 -0500 Subject: [PATCH 2/2] Update project metadata for ASCellNode.m -> ASCellNode.mm --- AsyncDisplayKit.xcodeproj/project.pbxproj | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/AsyncDisplayKit.xcodeproj/project.pbxproj b/AsyncDisplayKit.xcodeproj/project.pbxproj index cd8d5a071c..5440ca472c 100644 --- a/AsyncDisplayKit.xcodeproj/project.pbxproj +++ b/AsyncDisplayKit.xcodeproj/project.pbxproj @@ -345,10 +345,10 @@ AC3C4A511A1139C100143C57 /* ASCollectionView.h in Headers */ = {isa = PBXBuildFile; fileRef = AC3C4A4F1A1139C100143C57 /* ASCollectionView.h */; settings = {ATTRIBUTES = (Public, ); }; }; AC3C4A521A1139C100143C57 /* ASCollectionView.mm in Sources */ = {isa = PBXBuildFile; fileRef = AC3C4A501A1139C100143C57 /* ASCollectionView.mm */; }; AC3C4A541A113EEC00143C57 /* ASCollectionViewProtocols.h in Headers */ = {isa = PBXBuildFile; fileRef = AC3C4A531A113EEC00143C57 /* ASCollectionViewProtocols.h */; settings = {ATTRIBUTES = (Public, ); }; }; - AC47D9421B3B891B00AAEE9D /* ASCellNode.m in Sources */ = {isa = PBXBuildFile; fileRef = AC6456071B0A335000CF11B8 /* ASCellNode.m */; }; + AC47D9421B3B891B00AAEE9D /* ASCellNode.mm in Sources */ = {isa = PBXBuildFile; fileRef = AC6456071B0A335000CF11B8 /* ASCellNode.mm */; }; AC47D9451B3BB41900AAEE9D /* ASRelativeSize.h in Headers */ = {isa = PBXBuildFile; fileRef = AC47D9431B3BB41900AAEE9D /* ASRelativeSize.h */; settings = {ATTRIBUTES = (Public, ); }; }; AC47D9461B3BB41900AAEE9D /* ASRelativeSize.mm in Sources */ = {isa = PBXBuildFile; fileRef = AC47D9441B3BB41900AAEE9D /* ASRelativeSize.mm */; }; - AC6456091B0A335000CF11B8 /* ASCellNode.m in Sources */ = {isa = PBXBuildFile; fileRef = AC6456071B0A335000CF11B8 /* ASCellNode.m */; }; + AC6456091B0A335000CF11B8 /* ASCellNode.mm in Sources */ = {isa = PBXBuildFile; fileRef = AC6456071B0A335000CF11B8 /* ASCellNode.mm */; }; AC7A2C171BDE11DF0093FE1A /* ASTableViewInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = AC7A2C161BDE11DF0093FE1A /* ASTableViewInternal.h */; }; AC7A2C181BDE11DF0093FE1A /* ASTableViewInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = AC7A2C161BDE11DF0093FE1A /* ASTableViewInternal.h */; }; ACC945A91BA9E7A0005E1FB8 /* ASViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = ACC945A81BA9E7A0005E1FB8 /* ASViewController.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -809,7 +809,7 @@ AC3C4A531A113EEC00143C57 /* ASCollectionViewProtocols.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASCollectionViewProtocols.h; sourceTree = ""; }; AC47D9431B3BB41900AAEE9D /* ASRelativeSize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASRelativeSize.h; path = AsyncDisplayKit/Layout/ASRelativeSize.h; sourceTree = ""; }; AC47D9441B3BB41900AAEE9D /* ASRelativeSize.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = ASRelativeSize.mm; path = AsyncDisplayKit/Layout/ASRelativeSize.mm; sourceTree = ""; }; - AC6456071B0A335000CF11B8 /* ASCellNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASCellNode.m; sourceTree = ""; }; + AC6456071B0A335000CF11B8 /* ASCellNode.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASCellNode.mm; sourceTree = ""; }; AC7A2C161BDE11DF0093FE1A /* ASTableViewInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASTableViewInternal.h; sourceTree = ""; }; ACC945A81BA9E7A0005E1FB8 /* ASViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASViewController.h; sourceTree = ""; }; ACC945AA1BA9E7C1005E1FB8 /* ASViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASViewController.m; sourceTree = ""; }; @@ -1020,7 +1020,7 @@ AEEC47DF1C20C2DD00EC1693 /* ASVideoNode.h */, AEEC47E01C20C2DD00EC1693 /* ASVideoNode.mm */, 055F1A3A19ABD43F004DAFF1 /* ASCellNode.h */, - AC6456071B0A335000CF11B8 /* ASCellNode.m */, + AC6456071B0A335000CF11B8 /* ASCellNode.mm */, 18C2ED7C1B9B7DE800F627B3 /* ASCollectionNode.h */, 18C2ED7D1B9B7DE800F627B3 /* ASCollectionNode.mm */, B13CA0FF1C52004900E031AB /* ASCollectionNode+Beta.h */, @@ -1939,7 +1939,7 @@ ACF6ED1B1B17843500DA7C62 /* ASBackgroundLayoutSpec.mm in Sources */, 0549634A1A1EA066000F8E56 /* ASBasicImageDownloader.mm in Sources */, 299DA1AA1A828D2900162D41 /* ASBatchContext.mm in Sources */, - AC6456091B0A335000CF11B8 /* ASCellNode.m in Sources */, + AC6456091B0A335000CF11B8 /* ASCellNode.mm in Sources */, DE8BEAC31C2DF3FC00D57C12 /* ASDelegateProxy.m in Sources */, ACF6ED1D1B17843500DA7C62 /* ASCenterLayoutSpec.mm in Sources */, 18C2ED801B9B7DE800F627B3 /* ASCollectionNode.mm in Sources */, @@ -2098,7 +2098,7 @@ DE8BEAC41C2DF3FC00D57C12 /* ASDelegateProxy.m in Sources */, B35062141B010EFD0018CF92 /* ASBasicImageDownloader.mm in Sources */, B35062161B010EFD0018CF92 /* ASBatchContext.mm in Sources */, - AC47D9421B3B891B00AAEE9D /* ASCellNode.m in Sources */, + AC47D9421B3B891B00AAEE9D /* ASCellNode.mm in Sources */, 34EFC7641B701CC600AD841F /* ASCenterLayoutSpec.mm in Sources */, 18C2ED831B9B7DE800F627B3 /* ASCollectionNode.mm in Sources */, E55D86331CA8A14000A0C26F /* ASLayoutable.mm in Sources */,