From fb18e7635b46368084418f3eb0cb7eea54859431 Mon Sep 17 00:00:00 2001 From: Huy Nguyen Date: Thu, 29 Oct 2015 21:26:06 +0200 Subject: [PATCH] Notify ASCellNodeDelegate even if a relayout doesn't result in a resize If the delegate is an ASTableView, relayoutAnimation will still be considered for animation. --- AsyncDisplayKit/ASCellNode.h | 13 +++++-------- AsyncDisplayKit/ASCellNode.m | 9 +++------ AsyncDisplayKit/ASCollectionView.mm | 2 +- AsyncDisplayKit/ASTableView.mm | 2 +- examples/Kittens/Sample/KittenNode.mm | 12 +----------- 5 files changed, 11 insertions(+), 27 deletions(-) diff --git a/AsyncDisplayKit/ASCellNode.h b/AsyncDisplayKit/ASCellNode.h index fcc55411a7..7d3bdfd583 100644 --- a/AsyncDisplayKit/ASCellNode.h +++ b/AsyncDisplayKit/ASCellNode.h @@ -15,16 +15,14 @@ typedef NSUInteger ASCellNodeAnimation; @protocol ASCellNodeDelegate /** - * Notifies the delegate that the specified cell node has done a relayout that results in a new size. + * Notifies the delegate that the specified cell node has done a relayout. * The notification is done on main thread. * * @param node A node informing the delegate about the relayout. * - * @param newSize A new size that is resulted in the relayout. - * - * @param suggestedAnimation A constant that indicates how the delegate should animate. See UITableViewRowAnimation. + * @param suggestedAnimation A constant indicates how the delegate should animate. See UITableViewRowAnimation. */ -- (void)node:(ASCellNode *)node didRelayoutToNewSize:(CGSize)newSize suggestedAnimation:(ASCellNodeAnimation)animation; +- (void)node:(ASCellNode *)node didRelayoutWithSuggestedAnimation:(ASCellNodeAnimation)animation; @end /** @@ -72,7 +70,7 @@ typedef NSUInteger ASCellNodeAnimation; @property (nonatomic, assign) BOOL highlighted; /* - * A delegate to be notified (on main thread) after a relayout that results in a new size. + * A delegate to be notified (on main thread) after a relayout. */ @property (nonatomic, weak) id delegate; @@ -97,8 +95,7 @@ typedef NSUInteger ASCellNodeAnimation; * * 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. - * - * If the relayout causes a change in size, the delegate will be notified on main thread. + * 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). */ diff --git a/AsyncDisplayKit/ASCellNode.m b/AsyncDisplayKit/ASCellNode.m index 1a1d58b5e7..37df35e864 100644 --- a/AsyncDisplayKit/ASCellNode.m +++ b/AsyncDisplayKit/ASCellNode.m @@ -53,15 +53,12 @@ - (void)setNeedsLayout { - ASDisplayNodeAssertThreadAffinity(self); - - CGSize oldSize = self.calculatedSize; + ASDisplayNodeAssertThreadAffinity(self); [super setNeedsLayout]; - CGSize newSize = self.calculatedSize; - if (_delegate != nil && !CGSizeEqualToSize(oldSize, newSize)) { + if (_delegate != nil) { ASPerformBlockOnMainThread(^{ - [_delegate node:self didRelayoutToNewSize:newSize suggestedAnimation:_relayoutAnimation]; + [_delegate node:self didRelayoutWithSuggestedAnimation:_relayoutAnimation]; }); } } diff --git a/AsyncDisplayKit/ASCollectionView.mm b/AsyncDisplayKit/ASCollectionView.mm index 6be2a94aa0..0e16ce3120 100644 --- a/AsyncDisplayKit/ASCollectionView.mm +++ b/AsyncDisplayKit/ASCollectionView.mm @@ -901,7 +901,7 @@ static BOOL _isInterceptedSelector(SEL sel) #pragma mark - ASCellNodeDelegate -- (void)node:(ASCellNode *)node didRelayoutToNewSize:(CGSize)newSize suggestedAnimation:(ASCellNodeAnimation)animation +- (void)node:(ASCellNode *)node didRelayoutWithSuggestedAnimation:(ASCellNodeAnimation)animation { ASDisplayNodeAssertMainThread(); NSIndexPath *indexPath = [self indexPathForNode:node]; diff --git a/AsyncDisplayKit/ASTableView.mm b/AsyncDisplayKit/ASTableView.mm index 2ae576e6ca..e1e91cee61 100644 --- a/AsyncDisplayKit/ASTableView.mm +++ b/AsyncDisplayKit/ASTableView.mm @@ -917,7 +917,7 @@ void ASPerformBlockWithoutAnimation(BOOL withoutAnimation, void (^block)()) { #pragma mark - ASCellNodeDelegate -- (void)node:(ASCellNode *)node didRelayoutToNewSize:(CGSize)newSize suggestedAnimation:(ASCellNodeAnimation)animation +- (void)node:(ASCellNode *)node didRelayoutWithSuggestedAnimation:(ASCellNodeAnimation)animation { ASDisplayNodeAssertMainThread(); NSIndexPath *indexPath = [self indexPathForNode:node]; diff --git a/examples/Kittens/Sample/KittenNode.mm b/examples/Kittens/Sample/KittenNode.mm index adc656aa22..847a2629c7 100644 --- a/examples/Kittens/Sample/KittenNode.mm +++ b/examples/Kittens/Sample/KittenNode.mm @@ -191,17 +191,7 @@ static const CGFloat kInnerPadding = 10.0f; - (void)toggleNodesSwap { _swappedTextAndImage = !_swappedTextAndImage; - - [UIView animateWithDuration:0.15 animations:^{ - self.alpha = 0; - } completion:^(BOOL finished) { - [self setNeedsLayout]; - [self.view layoutIfNeeded]; - - [UIView animateWithDuration:0.15 animations:^{ - self.alpha = 1; - }]; - }]; + [self setNeedsLayout]; } @end