Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Switch to Delegate from DataSource.
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahmbanana committed Jun 23, 2016
1 parent fbf7c30 commit 14fdafd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
24 changes: 12 additions & 12 deletions AsyncDisplayKit/ASTableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,18 +357,6 @@ NS_ASSUME_NONNULL_BEGIN

- (ASCellNodeBlock)tableView:(ASTableView *)tableView nodeBlockForRowAtIndexPath:(NSIndexPath *)indexPath;

/**
* Provides the constrained size range for measuring the row at the index path.
* Note: the widths in the returned size range are ignored!
*
* @param tableView The sender.
*
* @param indexPath The index path of the node.
*
* @returns A constrained size range for layout the node at this index path.
*/
- (ASSizeRange)tableView:(ASTableView *)tableView constrainedSizeForRowAtIndexPath:(NSIndexPath *)indexPath;

/**
* Indicator to lock the data source for data fetching in async mode.
* We should not update the data source until the data source has been unlocked. Otherwise, it will incur data inconsistency or exception
Expand Down Expand Up @@ -453,6 +441,18 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (BOOL)shouldBatchFetchForTableView:(ASTableView *)tableView;

/**
* Provides the constrained size range for measuring the row at the index path.
* Note: the widths in the returned size range are ignored!
*
* @param tableView The sender.
*
* @param indexPath The index path of the node.
*
* @returns A constrained size range for layout the node at this index path.
*/
- (ASSizeRange)tableView:(ASTableView *)tableView constrainedSizeForRowAtIndexPath:(NSIndexPath *)indexPath;

/**
* Informs the delegate that the table view did remove the node which was previously
* at the given index path from the view hierarchy.
Expand Down
13 changes: 7 additions & 6 deletions AsyncDisplayKit/ASTableView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ @interface ASTableView () <ASRangeControllerDataSource, ASRangeControllerDelegat
unsigned int asyncDelegateScrollViewWillEndDraggingWithVelocityTargetContentOffset:1;
unsigned int asyncDelegateTableViewWillBeginBatchFetchWithContext:1;
unsigned int asyncDelegateShouldBatchFetchForTableView:1;
unsigned int asyncDelegateTableViewConstrainedSizeForRowAtIndexPath:1;
} _asyncDelegateFlags;

struct {
unsigned int asyncDataSourceNumberOfSectionsInTableView:1;
unsigned int asyncDataSourceTableViewNodeBlockForRowAtIndexPath:1;
unsigned int asyncDataSourceTableViewConstrainedSizeForRowAtIndexPath:1;
unsigned int asyncDataSourceTableViewNodeForRowAtIndexPath:1;
unsigned int asyncDataSourceTableViewLockDataSource:1;
unsigned int asyncDataSourceTableViewUnlockDataSource:1;
Expand Down Expand Up @@ -292,7 +292,6 @@ - (void)setAsyncDataSource:(id<ASTableViewDataSource>)asyncDataSource
_asyncDataSourceFlags.asyncDataSourceNumberOfSectionsInTableView = [_asyncDataSource respondsToSelector:@selector(numberOfSectionsInTableView:)];
_asyncDataSourceFlags.asyncDataSourceTableViewNodeForRowAtIndexPath = [_asyncDataSource respondsToSelector:@selector(tableView:nodeForRowAtIndexPath:)];
_asyncDataSourceFlags.asyncDataSourceTableViewNodeBlockForRowAtIndexPath = [_asyncDataSource respondsToSelector:@selector(tableView:nodeBlockForRowAtIndexPath:)];
_asyncDataSourceFlags.asyncDataSourceTableViewConstrainedSizeForRowAtIndexPath = [_asyncDataSource respondsToSelector:@selector(tableView:constrainedSizeForRowAtIndexPath:)];
_asyncDataSourceFlags.asyncDataSourceTableViewLockDataSource = [_asyncDataSource respondsToSelector:@selector(tableViewLockDataSource:)];
_asyncDataSourceFlags.asyncDataSourceTableViewUnlockDataSource = [_asyncDataSource respondsToSelector:@selector(tableViewUnlockDataSource:)];

Expand Down Expand Up @@ -329,6 +328,8 @@ - (void)setAsyncDelegate:(id<ASTableViewDelegate>)asyncDelegate
_asyncDelegateFlags.asyncDelegateShouldBatchFetchForTableView = [_asyncDelegate respondsToSelector:@selector(shouldBatchFetchForTableView:)];
_asyncDelegateFlags.asyncDelegateScrollViewWillBeginDragging = [_asyncDelegate respondsToSelector:@selector(scrollViewWillBeginDragging:)];
_asyncDelegateFlags.asyncDelegateScrollViewDidEndDragging = [_asyncDelegate respondsToSelector:@selector(scrollViewDidEndDragging:willDecelerate:)];
_asyncDelegateFlags.asyncDelegateTableViewConstrainedSizeForRowAtIndexPath = [_asyncDelegate respondsToSelector:@selector(tableView:constrainedSizeForRowAtIndexPath:)];

}

super.delegate = (id<UITableViewDelegate>)_proxyDelegate;
Expand Down Expand Up @@ -1083,11 +1084,11 @@ - (ASCellNodeBlock)dataController:(ASDataController *)dataController nodeBlockAt
- (ASSizeRange)dataController:(ASDataController *)dataController constrainedSizeForNodeAtIndexPath:(NSIndexPath *)indexPath
{
ASSizeRange constrainedSize = kInvalidSizeRange;
if (_asyncDataSourceFlags.asyncDataSourceTableViewConstrainedSizeForRowAtIndexPath) {
ASSizeRange dataSourceConstrainedSize = [_asyncDataSource tableView:self constrainedSizeForRowAtIndexPath:indexPath];
if (_asyncDelegateFlags.asyncDelegateTableViewConstrainedSizeForRowAtIndexPath) {
ASSizeRange delegateConstrainedSize = [_asyncDelegate tableView:self constrainedSizeForRowAtIndexPath:indexPath];
// ignore widths in the returned size range (for TableView)
constrainedSize = ASSizeRangeMake(CGSizeMake(_nodesConstrainedWidth, dataSourceConstrainedSize.min.height),
CGSizeMake(_nodesConstrainedWidth, dataSourceConstrainedSize.max.height));
constrainedSize = ASSizeRangeMake(CGSizeMake(_nodesConstrainedWidth, delegateConstrainedSize.min.height),
CGSizeMake(_nodesConstrainedWidth, delegateConstrainedSize.max.height));
} else {
constrainedSize = ASSizeRangeMake(CGSizeMake(_nodesConstrainedWidth, 0),
CGSizeMake(_nodesConstrainedWidth, FLT_MAX));
Expand Down

0 comments on commit 14fdafd

Please sign in to comment.