mirror of
https://github.com/HackPlan/AsyncDisplayKit.git
synced 2026-04-01 12:23:20 +08:00
[ASDisplayNode] Add Convenience Interface State Accessors (#2168)
* Finish renaming fetchData range, add convenience accessors * Update example * Update new tests
This commit is contained in:
@@ -204,18 +204,18 @@
|
||||
ASRangeTuningParameters fullPreloadParams = { .leadingBufferScreenfuls = 1, .trailingBufferScreenfuls = 0.5 };
|
||||
|
||||
[collectionView setTuningParameters:minimumRenderParams forRangeMode:ASLayoutRangeModeMinimum rangeType:ASLayoutRangeTypeDisplay];
|
||||
[collectionView setTuningParameters:minimumPreloadParams forRangeMode:ASLayoutRangeModeMinimum rangeType:ASLayoutRangeTypeFetchData];
|
||||
[collectionView setTuningParameters:minimumPreloadParams forRangeMode:ASLayoutRangeModeMinimum rangeType:ASLayoutRangeTypePreload];
|
||||
[collectionView setTuningParameters:fullRenderParams forRangeMode:ASLayoutRangeModeFull rangeType:ASLayoutRangeTypeDisplay];
|
||||
[collectionView setTuningParameters:fullPreloadParams forRangeMode:ASLayoutRangeModeFull rangeType:ASLayoutRangeTypeFetchData];
|
||||
[collectionView setTuningParameters:fullPreloadParams forRangeMode:ASLayoutRangeModeFull rangeType:ASLayoutRangeTypePreload];
|
||||
|
||||
XCTAssertTrue(ASRangeTuningParametersEqualToRangeTuningParameters(minimumRenderParams,
|
||||
[collectionView tuningParametersForRangeMode:ASLayoutRangeModeMinimum rangeType:ASLayoutRangeTypeDisplay]));
|
||||
XCTAssertTrue(ASRangeTuningParametersEqualToRangeTuningParameters(minimumPreloadParams,
|
||||
[collectionView tuningParametersForRangeMode:ASLayoutRangeModeMinimum rangeType:ASLayoutRangeTypeFetchData]));
|
||||
[collectionView tuningParametersForRangeMode:ASLayoutRangeModeMinimum rangeType:ASLayoutRangeTypePreload]));
|
||||
XCTAssertTrue(ASRangeTuningParametersEqualToRangeTuningParameters(fullRenderParams,
|
||||
[collectionView tuningParametersForRangeMode:ASLayoutRangeModeFull rangeType:ASLayoutRangeTypeDisplay]));
|
||||
XCTAssertTrue(ASRangeTuningParametersEqualToRangeTuningParameters(fullPreloadParams,
|
||||
[collectionView tuningParametersForRangeMode:ASLayoutRangeModeFull rangeType:ASLayoutRangeTypeFetchData]));
|
||||
[collectionView tuningParametersForRangeMode:ASLayoutRangeModeFull rangeType:ASLayoutRangeTypePreload]));
|
||||
}
|
||||
|
||||
- (void)testTuningParameters
|
||||
@@ -227,10 +227,10 @@
|
||||
ASRangeTuningParameters preloadParams = { .leadingBufferScreenfuls = 4.3, .trailingBufferScreenfuls = 2.3 };
|
||||
|
||||
[collectionView setTuningParameters:renderParams forRangeType:ASLayoutRangeTypeDisplay];
|
||||
[collectionView setTuningParameters:preloadParams forRangeType:ASLayoutRangeTypeFetchData];
|
||||
[collectionView setTuningParameters:preloadParams forRangeType:ASLayoutRangeTypePreload];
|
||||
|
||||
XCTAssertTrue(ASRangeTuningParametersEqualToRangeTuningParameters(renderParams, [collectionView tuningParametersForRangeType:ASLayoutRangeTypeDisplay]));
|
||||
XCTAssertTrue(ASRangeTuningParametersEqualToRangeTuningParameters(preloadParams, [collectionView tuningParametersForRangeType:ASLayoutRangeTypeFetchData]));
|
||||
XCTAssertTrue(ASRangeTuningParametersEqualToRangeTuningParameters(preloadParams, [collectionView tuningParametersForRangeType:ASLayoutRangeTypePreload]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1733,9 +1733,9 @@ static inline BOOL _CGPointEqualToPointWithEpsilon(CGPoint point1, CGPoint point
|
||||
|
||||
// Simulate range handler updating cell node.
|
||||
[cellNode addSubnode:node];
|
||||
[cellNode enterInterfaceState:ASInterfaceStateFetchData];
|
||||
[cellNode enterInterfaceState:ASInterfaceStatePreload];
|
||||
XCTAssert(node.hasFetchedData);
|
||||
XCTAssert(node.interfaceState == ASInterfaceStateFetchData);
|
||||
XCTAssert(node.interfaceState == ASInterfaceStatePreload);
|
||||
|
||||
// If the node goes into a view it should not adopt the `InHierarchy` state.
|
||||
ASTestWindow *window = [ASTestWindow new];
|
||||
@@ -1749,7 +1749,7 @@ static inline BOOL _CGPointEqualToPointWithEpsilon(CGPoint point1, CGPoint point
|
||||
ASCellNode *cellNode = [ASCellNode new];
|
||||
ASTestDisplayNode *node = [ASTestDisplayNode new];
|
||||
[cellNode addSubnode:node];
|
||||
[cellNode enterInterfaceState:ASInterfaceStateFetchData];
|
||||
[cellNode enterInterfaceState:ASInterfaceStatePreload];
|
||||
node.hasFetchedData = NO;
|
||||
[cellNode setNeedsDataFetch];
|
||||
XCTAssert(node.hasFetchedData);
|
||||
@@ -1763,10 +1763,10 @@ static inline BOOL _CGPointEqualToPointWithEpsilon(CGPoint point1, CGPoint point
|
||||
[cellNode setHierarchyState:ASHierarchyStateRangeManaged];
|
||||
|
||||
// Simulate enter range, fetch data, exit range
|
||||
[cellNode enterInterfaceState:ASInterfaceStateFetchData];
|
||||
[cellNode exitInterfaceState:ASInterfaceStateFetchData];
|
||||
[cellNode enterInterfaceState:ASInterfaceStatePreload];
|
||||
[cellNode exitInterfaceState:ASInterfaceStatePreload];
|
||||
node.hasFetchedData = NO;
|
||||
[cellNode enterInterfaceState:ASInterfaceStateFetchData];
|
||||
[cellNode enterInterfaceState:ASInterfaceStatePreload];
|
||||
|
||||
XCTAssert(node.hasFetchedData);
|
||||
}
|
||||
@@ -1891,25 +1891,25 @@ static bool stringContainsPointer(NSString *description, id p) {
|
||||
ASTestDisplayNode *node = [[ASTestDisplayNode alloc] init];
|
||||
|
||||
[node recursivelySetInterfaceState:ASInterfaceStateDisplay];
|
||||
[node recursivelySetInterfaceState:ASInterfaceStateFetchData];
|
||||
[node recursivelySetInterfaceState:ASInterfaceStatePreload];
|
||||
|
||||
XCTAssert([node displayRangeStateChangedToNO]);
|
||||
}
|
||||
|
||||
- (void)testDidEnterPreloadIsCalledWhenNodesEnterFetchDataRange
|
||||
- (void)testDidEnterPreloadIsCalledWhenNodesEnterPreloadRange
|
||||
{
|
||||
ASTestDisplayNode *node = [[ASTestDisplayNode alloc] init];
|
||||
|
||||
[node recursivelySetInterfaceState:ASInterfaceStateFetchData];
|
||||
[node recursivelySetInterfaceState:ASInterfaceStatePreload];
|
||||
|
||||
XCTAssert([node preloadStateChangedToYES]);
|
||||
}
|
||||
|
||||
- (void)testDidExitPreloadIsCalledWhenNodesExitFetchDataRange
|
||||
- (void)testDidExitPreloadIsCalledWhenNodesExitPreloadRange
|
||||
{
|
||||
ASTestDisplayNode *node = [[ASTestDisplayNode alloc] init];
|
||||
|
||||
[node recursivelySetInterfaceState:ASInterfaceStateFetchData];
|
||||
[node recursivelySetInterfaceState:ASInterfaceStatePreload];
|
||||
[node recursivelySetInterfaceState:ASInterfaceStateDisplay];
|
||||
|
||||
XCTAssert([node preloadStateChangedToNO]);
|
||||
@@ -1977,11 +1977,11 @@ static bool stringContainsPointer(NSString *description, id p) {
|
||||
|
||||
[node view]; // Node needs to be loaded
|
||||
|
||||
[node enterInterfaceState:ASInterfaceStateFetchData];
|
||||
[node enterInterfaceState:ASInterfaceStatePreload];
|
||||
|
||||
|
||||
XCTAssertTrue((node.interfaceState & ASInterfaceStateFetchData) == ASInterfaceStateFetchData);
|
||||
XCTAssertTrue((subnode.interfaceState & ASInterfaceStateFetchData) == ASInterfaceStateFetchData);
|
||||
XCTAssertTrue((node.interfaceState & ASInterfaceStatePreload) == ASInterfaceStatePreload);
|
||||
XCTAssertTrue((subnode.interfaceState & ASInterfaceStatePreload) == ASInterfaceStatePreload);
|
||||
XCTAssertTrue(node.hasFetchedData);
|
||||
XCTAssertTrue(subnode.hasFetchedData);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
|
||||
- (void)doOnPlayIfVideoIsNotReadyInitializeSpinnerAndAddAsSubnodeWithUrl
|
||||
{
|
||||
_videoNode.interfaceState = ASInterfaceStateFetchData;
|
||||
_videoNode.interfaceState = ASInterfaceStatePreload;
|
||||
[_videoNode play];
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@
|
||||
|
||||
- (void)doOnPauseSpinnerIsPausedIfPresentWithURL
|
||||
{
|
||||
_videoNode.interfaceState = ASInterfaceStateFetchData;
|
||||
_videoNode.interfaceState = ASInterfaceStatePreload;
|
||||
|
||||
[_videoNode play];
|
||||
[_videoNode pause];
|
||||
@@ -114,7 +114,7 @@
|
||||
|
||||
- (void)doOnVideoReadySpinnerIsStoppedAndRemovedWithURL
|
||||
{
|
||||
_videoNode.interfaceState = ASInterfaceStateFetchData;
|
||||
_videoNode.interfaceState = ASInterfaceStatePreload;
|
||||
|
||||
[_videoNode play];
|
||||
[_videoNode observeValueForKeyPath:@"status" ofObject:[_videoNode currentItem] change:@{NSKeyValueChangeNewKey : @(AVPlayerItemStatusReadyToPlay)} context:NULL];
|
||||
@@ -144,7 +144,7 @@
|
||||
[[[videoNodeMock expect] andForwardToRealObject] prepareToPlayAsset:assetMock withKeys:_requestedKeys];
|
||||
|
||||
_videoNode.asset = assetMock;
|
||||
_videoNode.interfaceState = ASInterfaceStateFetchData;
|
||||
_videoNode.interfaceState = ASInterfaceStatePreload;
|
||||
|
||||
[videoNodeMock verifyWithDelay:1.0f];
|
||||
|
||||
@@ -162,7 +162,7 @@
|
||||
[[[videoNodeMock expect] andForwardToRealObject] prepareToPlayAsset:assetMock withKeys:_requestedKeys];
|
||||
|
||||
_videoNode.asset = assetMock;
|
||||
_videoNode.interfaceState = ASInterfaceStateFetchData;
|
||||
_videoNode.interfaceState = ASInterfaceStatePreload;
|
||||
|
||||
[videoNodeMock verifyWithDelay:1.0f];
|
||||
|
||||
@@ -311,7 +311,7 @@
|
||||
_videoNode.shouldAutorepeat = NO;
|
||||
|
||||
[_videoNode didLoad];
|
||||
[_videoNode setInterfaceState:ASInterfaceStateVisible | ASInterfaceStateDisplay | ASInterfaceStateFetchData];
|
||||
[_videoNode setInterfaceState:ASInterfaceStateVisible | ASInterfaceStateDisplay | ASInterfaceStatePreload];
|
||||
[_videoNode prepareToPlayAsset:assetMock withKeys:_requestedKeys];
|
||||
[_videoNode play];
|
||||
|
||||
@@ -332,7 +332,7 @@
|
||||
_videoNode.shouldAutorepeat = YES;
|
||||
|
||||
[_videoNode didLoad];
|
||||
[_videoNode setInterfaceState:ASInterfaceStateVisible | ASInterfaceStateDisplay | ASInterfaceStateFetchData];
|
||||
[_videoNode setInterfaceState:ASInterfaceStateVisible | ASInterfaceStateDisplay | ASInterfaceStatePreload];
|
||||
[_videoNode prepareToPlayAsset:assetMock withKeys:_requestedKeys];
|
||||
[_videoNode play];
|
||||
|
||||
@@ -348,7 +348,7 @@
|
||||
|
||||
_videoNode.asset = assetMock;
|
||||
|
||||
[_videoNode setInterfaceState:ASInterfaceStateVisible | ASInterfaceStateDisplay | ASInterfaceStateFetchData];
|
||||
[_videoNode setInterfaceState:ASInterfaceStateVisible | ASInterfaceStateDisplay | ASInterfaceStatePreload];
|
||||
[_videoNode prepareToPlayAsset:assetMock withKeys:_requestedKeys];
|
||||
[_videoNode pause];
|
||||
_videoNode.shouldBePlaying = YES;
|
||||
|
||||
Reference in New Issue
Block a user