Add relayout item/row APIs to ASTableView and ASCollectionView.

This commit is contained in:
Huy Nguyen 2015-10-07 21:23:12 +03:00
parent 697142240c
commit f13f61c2f0
7 changed files with 46 additions and 6 deletions

View File

@ -191,6 +191,16 @@
*/
- (void)reloadItemsAtIndexPaths:(NSArray *)indexPaths;
/**
* Relayouts the specified item.
*
* @param indexPath The index path identifying the item to relayout.
*
* @discussion This method must be called from the main thread. The relayout is excuted on main thread.
* The node of the specified item must be updated to cause layout changes before this method is called.
*/
- (void)relayoutItemAtIndexPath:(NSIndexPath *)indexPath;
/**
* Moves the item at a specified location to a destination location.
*

View File

@ -406,6 +406,14 @@ static BOOL _isInterceptedSelector(SEL sel)
[_dataController reloadRowsAtIndexPaths:indexPaths withAnimationOptions:kASCollectionViewAnimationNone];
}
- (void)relayoutItemAtIndexPath:(NSIndexPath *)indexPath
{
ASDisplayNodeAssertMainThread();
ASCellNode *node = [self nodeForItemAtIndexPath:indexPath];
[node setNeedsLayout];
[super reloadItemsAtIndexPaths:@[indexPath]];
}
- (void)moveItemAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath
{
ASDisplayNodeAssertMainThread();

View File

@ -556,9 +556,13 @@ 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: If the relayout causes a change in size of the root node that is attached to a container view
* (table or collection view, for example), the container view must be notified to relayout.
* For ASTableView and ASCollectionView, an empty batch editing transaction must be triggered to animate to new row / item sizes.
* Note: If the relayout causes a change in size of the root node that is attached to a container view,
* the container view must be notified to relayout.
* For ASTableView and ASCollectionView, instead of calling this method directly,
* it is recommended to call -relayoutRowAtIndexPath:withRowAnimation and -relayoutItemAtIndexPath: respectively.
*
* @see [ASTableView relayoutRowAtIndexPath:withRowAnimation:]
* @see [ASCollectionView relayoutItemAtIndexPath:]
*/
- (void)setNeedsLayout;

View File

@ -206,6 +206,18 @@
*/
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
/**
* Relayouts the specified row using a given animation effect.
*
* @param indexPath The index path identifying the row to relayout.
*
* @param animation A constant that indicates how the relayout is to be animated. See UITableViewRowAnimation.
*
* @discussion This method must be called from the main thread. The relayout is excuted on main thread.
* The node of the specified row must be updated to cause layout changes before this method is called.
*/
- (void)relayoutRowAtIndexPath:(NSIndexPath *)indexPath withRowAnimation:(UITableViewRowAnimation)animation;
/**
* Moves the row at a specified location to a destination location.
*

View File

@ -455,6 +455,14 @@ void ASPerformBlockWithoutAnimation(BOOL withoutAnimation, void (^block)()) {
[_dataController reloadRowsAtIndexPaths:indexPaths withAnimationOptions:animation];
}
- (void)relayoutRowAtIndexPath:(NSIndexPath *)indexPath withRowAnimation:(UITableViewRowAnimation)animation
{
ASDisplayNodeAssertMainThread();
ASCellNode *node = [self nodeForRowAtIndexPath:indexPath];
[node setNeedsLayout];
[super reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:animation];
}
- (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath
{
ASDisplayNodeAssertMainThread();

View File

@ -185,7 +185,6 @@ static const CGFloat kInnerPadding = 10.0f;
- (void)toggleImageEnlargement
{
_isImageEnlarged = !_isImageEnlarged;
[self setNeedsLayout];
}
- (void)toggleNodesSwap

View File

@ -118,11 +118,10 @@ static const NSInteger kMaxLitterSize = 100; // max number of kitten cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[_tableView deselectRowAtIndexPath:indexPath animated:YES];
[_tableView beginUpdates];
// Assume only kitten nodes are selectable (see -tableView:shouldHighlightRowAtIndexPath:).
KittenNode *node = (KittenNode *)[_tableView nodeForRowAtIndexPath:indexPath];
[node toggleImageEnlargement];
[_tableView endUpdates];
[_tableView relayoutRowAtIndexPath:indexPath withRowAnimation:UITableViewRowAnimationAutomatic];
}
- (ASCellNode *)tableView:(ASTableView *)tableView nodeForRowAtIndexPath:(NSIndexPath *)indexPath