Range handlers use recursive actions

fixes #363
This commit is contained in:
Ryan Nystrom 2015-03-09 12:33:02 -07:00
parent 10adca52d0
commit 5e7755fac0
3 changed files with 20 additions and 3 deletions

View File

@ -331,10 +331,19 @@ typedef CALayer *(^ASDisplayNodeLayerBlock)();
* This method is used to notify the node that it should purge any content that is both expensive to fetch and to * This method is used to notify the node that it should purge any content that is both expensive to fetch and to
* retain in memory. * retain in memory.
* *
* @see fetchRemoteData * @see clearRemoteData and fetchRemoteData
*/ */
- (void)recursivelyClearRemoteData; - (void)recursivelyClearRemoteData;
/**
* @abstract Calls -fetchRemoteData on the receiver and its subnode hierarchy.
*
* @discussion Fetches content from remote sources for the current node and all subnodes.
*
* @see fetchRemoteData and clearRemoteData
*/
- (void)recursivelyFetchRemoteData;
/** /**
* @abstract Toggle displaying a placeholder over the node that covers content until the node and all subnodes are * @abstract Toggle displaying a placeholder over the node that covers content until the node and all subnodes are
* displayed. * displayed.

View File

@ -1348,6 +1348,14 @@ static NSInteger incrementIfFound(NSInteger i) {
// subclass override // subclass override
} }
- (void)recursivelyFetchRemoteData
{
for (ASDisplayNode *subnode in self.subnodes) {
[subnode recursivelyFetchRemoteData];
}
[self fetchRemoteData];
}
- (void)clearRemoteData - (void)clearRemoteData
{ {
// subclass override // subclass override

View File

@ -16,13 +16,13 @@
- (void)node:(ASDisplayNode *)node enteredRangeOfType:(ASLayoutRangeType)rangeType - (void)node:(ASDisplayNode *)node enteredRangeOfType:(ASLayoutRangeType)rangeType
{ {
ASDisplayNodeAssert(rangeType == ASLayoutRangeTypePreload, @"Preload delegate should not handle other ranges"); ASDisplayNodeAssert(rangeType == ASLayoutRangeTypePreload, @"Preload delegate should not handle other ranges");
[node fetchRemoteData]; [node recursivelyFetchRemoteData];
} }
- (void)node:(ASDisplayNode *)node exitedRangeOfType:(ASLayoutRangeType)rangeType - (void)node:(ASDisplayNode *)node exitedRangeOfType:(ASLayoutRangeType)rangeType
{ {
ASDisplayNodeAssert(rangeType == ASLayoutRangeTypePreload, @"Preload delegate should not handle other ranges"); ASDisplayNodeAssert(rangeType == ASLayoutRangeTypePreload, @"Preload delegate should not handle other ranges");
[node clearRemoteData]; [node recursivelyClearRemoteData];
} }
@end @end