Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions AsyncDisplayKit/ASCellNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ typedef NSUInteger ASCellNodeAnimation;
* The notification is done on main thread.
*
* @param node A node informing the delegate about the relayout.
*
* @param suggestedAnimation A constant indicates how the delegate should animate. See UITableViewRowAnimation.
*/
- (void)node:(ASCellNode *)node didRelayoutWithSuggestedAnimation:(ASCellNodeAnimation)animation;
- (void)nodeDidRelayout:(ASCellNode *)node;
@end

/**
Expand Down Expand Up @@ -74,13 +72,6 @@ typedef NSUInteger ASCellNodeAnimation;
*/
@property (nonatomic, weak) id<ASCellNodeLayoutDelegate> layoutDelegate;

/*
* A constant that is passed to the delegate to indicate how a relayout is to be animated.
*
* @see UITableViewRowAnimation
*/
@property (nonatomic, assign) ASCellNodeAnimation relayoutAnimation;

/*
* ASCellNode must forward touch events in order for UITableView and UICollectionView tap handling to work. Overriding
* these methods (e.g. for highlighting) requires the super method be called.
Expand All @@ -91,7 +82,7 @@ typedef NSUInteger ASCellNodeAnimation;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event ASDISPLAYNODE_REQUIRES_SUPER;

/**
* Marks the node as needing layout. Convenience for use whether the view / layer is loaded or not. Safe to call from a background thread.
* 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.
Expand Down
3 changes: 1 addition & 2 deletions AsyncDisplayKit/ASCellNode.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ - (instancetype)init
// use UITableViewCell defaults
_selectionStyle = UITableViewCellSelectionStyleDefault;
self.clipsToBounds = YES;
_relayoutAnimation = UITableViewRowAnimationAutomatic;

return self;
}
Expand Down Expand Up @@ -58,7 +57,7 @@ - (void)setNeedsLayout

if (_layoutDelegate != nil) {
ASPerformBlockOnMainThread(^{
[_layoutDelegate node:self didRelayoutWithSuggestedAnimation:_relayoutAnimation];
[_layoutDelegate nodeDidRelayout:self];
});
}
}
Expand Down
12 changes: 6 additions & 6 deletions AsyncDisplayKit/ASCollectionView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,9 @@ - (ASCellNode *)dataController:(ASDataController *)dataController nodeAtIndexPat
{
ASCellNode *node = [_asyncDataSource collectionView:self nodeForItemAtIndexPath:indexPath];
ASDisplayNodeAssert([node isKindOfClass:ASCellNode.class], @"invalid node class, expected ASCellNode");
node.layoutDelegate = self;
if (node.layoutDelegate == nil) {
node.layoutDelegate = self;
}
return node;
}

Expand Down Expand Up @@ -889,13 +891,11 @@ - (void)rangeController:(ASRangeController *)rangeController didDeleteSectionsAt

#pragma mark - ASCellNodeDelegate

- (void)node:(ASCellNode *)node didRelayoutWithSuggestedAnimation:(ASCellNodeAnimation)animation
- (void)nodeDidRelayout:(ASCellNode *)node
{
ASDisplayNodeAssertMainThread();
NSIndexPath *indexPath = [self indexPathForNode:node];
if (indexPath != nil) {
[super reloadItemsAtIndexPaths:@[indexPath]];
}
// Cause UICollectionView to requery for the new height of this node
[super performBatchUpdates:^{} completion:nil];
}

@end
3 changes: 3 additions & 0 deletions AsyncDisplayKit/ASDisplayNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,9 @@ typedef void (^ASDisplayNodeDidLoadBlock)(ASDisplayNode *node);
*
* 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.
*
* Note: ASCellNode has special behavior in that calling this method will automatically notify
* the containing ASTableView / ASCollectionView that the cell should be resized, if necessary.
*/
- (void)setNeedsLayout;

Expand Down
15 changes: 8 additions & 7 deletions AsyncDisplayKit/ASTableView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,9 @@ - (ASCellNode *)dataController:(ASDataController *)dataController nodeAtIndexPat
{
ASCellNode *node = [_asyncDataSource tableView:self nodeForRowAtIndexPath:indexPath];
ASDisplayNodeAssert([node isKindOfClass:ASCellNode.class], @"invalid node class, expected ASCellNode");
node.layoutDelegate = self;
if (node.layoutDelegate == nil) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nguyenhuy for my understanding, why is the check necessary before setting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to allow developers to set their own layout delegate (in -tableView:nodeForRowAtIndexPath). This checks make sure if developer indeed provides such delegate, it is not overridden here.

node.layoutDelegate = self;
}
return node;
}

Expand Down Expand Up @@ -895,15 +897,14 @@ - (void)willLayoutSubviewsOfTableViewCell:(_ASTableViewCell *)tableViewCell
}
}

#pragma mark - ASCellNodeDelegate
#pragma mark - ASCellNodeLayoutDelegate

- (void)node:(ASCellNode *)node didRelayoutWithSuggestedAnimation:(ASCellNodeAnimation)animation
- (void)nodeDidRelayout:(ASCellNode *)node
{
ASDisplayNodeAssertMainThread();
NSIndexPath *indexPath = [self indexPathForNode:node];
if (indexPath != nil) {
[super reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:(UITableViewRowAnimation)animation];
}
// Cause UITableView to requery for the new height of this node
[super beginUpdates];
[super endUpdates];
}

@end
12 changes: 11 additions & 1 deletion examples/Kittens/Sample/KittenNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,17 @@ - (void)toggleImageEnlargement
- (void)toggleNodesSwap
{
_swappedTextAndImage = !_swappedTextAndImage;
[self setNeedsLayout];

[UIView animateWithDuration:0.15 animations:^{
self.alpha = 0;
} completion:^(BOOL finished) {
[self setNeedsLayout];
[self.view layoutIfNeeded];

[UIView animateWithDuration:0.15 animations:^{
self.alpha = 1;
}];
}];
}

@end