Add setNeedsDataFetch method to queue off screen fetchData calls

This commit is contained in:
Levi McCallum
2016-01-27 14:52:37 -08:00
parent f696eb7476
commit ec7a3599bd
4 changed files with 48 additions and 3 deletions

View File

@@ -442,7 +442,6 @@ NS_ASSUME_NONNULL_BEGIN
*
* @see displaySuspended and setNeedsDisplay
*/
- (void)recursivelyClearContents;
/**
@@ -465,6 +464,13 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)recursivelyFetchData;
/**
* @abstract Marks the node as needing to call fetchData
* @discussion If the node is outside of the preload range, it is queued to call fetchData the next time it enters the range.
* Otherwise, fetchData is called immediately if the node is currently within the preload range.
*/
- (void)setNeedsDataFetch;
/**
* @abstract Toggle displaying a placeholder over the node that covers content until the node and all subnodes are
* displayed.

View File

@@ -1727,6 +1727,15 @@ static BOOL ShouldUseNewRenderingRange = YES;
// subclass override
}
- (void)setNeedsDataFetch
{
if (ASInterfaceStateIncludesFetchData(_interfaceState)) {
[self fetchData];
} else {
_needsDataFetch = YES;
}
}
// TODO: Replace this with ASDisplayNodePerformBlockOnEveryNode or enterInterfaceState:
- (void)recursivelyFetchData
{
@@ -1793,9 +1802,10 @@ static BOOL ShouldUseNewRenderingRange = YES;
BOOL nowFetchData = ASInterfaceStateIncludesFetchData(newState);
BOOL wasFetchData = ASInterfaceStateIncludesFetchData(oldState);
if (nowFetchData != wasFetchData) {
if (nowFetchData) {
if (nowFetchData != wasFetchData || _needsDataFetch) {
if (nowFetchData || _needsDataFetch) {
[self fetchData];
_needsDataFetch = NO;
} else {
if ([self supportsRangeManagedInterfaceState]) {
[self clearFetchedData];

View File

@@ -29,6 +29,33 @@ inline BOOL ASInterfaceStateIncludesFetchData(ASInterfaceState interfaceState)
return ((interfaceState & ASInterfaceStateFetchData) == ASInterfaceStateFetchData);
}
inline BOOL ASInterfaceStateIncludesMeasureLayout(ASInterfaceState interfaceState)
{
return ((interfaceState & ASInterfaceStateMeasureLayout) == ASInterfaceStateMeasureLayout);
}
inline NSString * _Nonnull NSStringFromASInterfaceState(ASInterfaceState interfaceState)
{
NSMutableString *result = [NSMutableString stringWithString:@"{ "];
if (interfaceState == ASInterfaceStateNone) {
[result appendString:@"No state"];
}
if (ASInterfaceStateIncludesMeasureLayout(interfaceState)) {
[result appendString:@"MeasureLayout"];
}
if (ASInterfaceStateIncludesFetchData(interfaceState)) {
[result appendString:@" - FetchData"];
}
if (ASInterfaceStateIncludesDisplay(interfaceState)) {
[result appendString:@" - Display"];
}
if (ASInterfaceStateIncludesVisible(interfaceState)) {
[result appendString:@" - Visible"];
}
[result appendString:@" }"];
return result;
}
NS_ASSUME_NONNULL_BEGIN
ASDISPLAYNODE_EXTERN_C_BEGIN

View File

@@ -101,6 +101,8 @@ typedef NS_OPTIONS(NSUInteger, ASDisplayNodeMethodOverrides)
ASDisplayNodeExtraIvars _extra;
BOOL _needsDataFetch;
#if TIME_DISPLAYNODE_OPS
@public
NSTimeInterval _debugTimeToCreateView;