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.
This commit is contained in:
Huy Nguyen
2015-10-29 21:26:06 +02:00
parent 5b8f7e978d
commit fb18e7635b
5 changed files with 11 additions and 27 deletions

View File

@@ -15,16 +15,14 @@ typedef NSUInteger ASCellNodeAnimation;
@protocol ASCellNodeDelegate <NSObject>
/**
* 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<ASCellNodeDelegate> 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).
*/

View File

@@ -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];
});
}
}

View File

@@ -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];

View File

@@ -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];

View File

@@ -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