Skip to content

Commit

Permalink
Assert node did load before did enter visible way 1 (TextureGroup#886)
Browse files Browse the repository at this point in the history
* fix SIMULATE_WEB_RESPONSE not imported TextureGroup#449

* Fix to make rangeMode update in right time

* access layer to load node before enter visible

* revert space
  • Loading branch information
wsdwsd0829 authored and mikezucc committed Nov 7, 2018
1 parent 258ef41 commit 8e4932e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## master
* Add your own contributions to the next release on the line below this with your name.
- [ASDisplayNode.m] Make sure node is loaded before enter visible. [Max Wang](https://github.com/wsdwsd0829). [#886](https://github.com/TextureGroup/Texture/pull/886)
- [ASTextNode2] Add improved support for all line-break modes in experimental text node. [Kevin Smith](https://github.com/wiseoldduck). [#1150](https://github.com/TextureGroup/Texture/pull/1150)
- [ASExperimentalFeatures.m] Fix mismatch name in experimental features. [Max Wang](https://github.com/wsdwsd0829). [#1159](https://github.com/TextureGroup/Texture/pull/1159)
- [ASCollectionViewLayoutController] Set default tuning parameters before view is loaded. [Max Wang](https://github.com/wsdwsd0829). [#1158](https://github.com/TextureGroup/Texture/pull/1158)
Expand Down
16 changes: 15 additions & 1 deletion Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2265,7 +2265,14 @@ - (void)_insertSubnode:(ASDisplayNode *)subnode atSubnodeIndex:(NSInteger)subnod
[_subnodes insertObject:subnode atIndex:subnodeIndex];
_cachedSubnodes = nil;
__instanceLock__.unlock();


if (!isRasterized && self.nodeLoaded) {
// Trigger the subnode to load its layer, which will create its view if it needs one.
// By doing this prior to downward propagation of .interfaceState in _setSupernode:,
// we can guarantee that -didEnterVisibleState is only called with .isNodeLoaded = YES.
[subnode layer];
}

// This call will apply our .hierarchyState to the new subnode.
// If we are a managed hierarchy, as in ASCellNode trees, it will also apply our .interfaceState.
[subnode _setSupernode:self];
Expand Down Expand Up @@ -3272,10 +3279,17 @@ - (void)didEnterVisibleState
{
// subclass override
ASDisplayNodeAssertMainThread();

// Rasterized node's loading state is merged with root node of rasterized tree.
if (!(self.hierarchyState & ASHierarchyStateRasterized)) {
ASDisplayNodeAssert(self.isNodeLoaded, @"Node should be loaded before entering visible state.");
}

ASAssertUnlocked(__instanceLock__);
[self enumerateInterfaceStateDelegates:^(id<ASInterfaceStateDelegate> del) {
[del didEnterVisibleState];
}];

#if AS_ENABLE_TIPS
[ASTipsController.shared nodeDidAppear:self];
#endif
Expand Down
1 change: 1 addition & 0 deletions Tests/ASNetworkImageNodeTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ - (void)DISABLED_testThatProgressBlockIsSetAndClearedCorrectlyOnVisibility

- (void)testThatProgressBlockIsSetAndClearedCorrectlyOnChangeURL
{
[node layer];
[node enterInterfaceState:ASInterfaceStateInHierarchy];

// Set URL while visible, should set progress block
Expand Down
12 changes: 7 additions & 5 deletions Tests/ASVideoNodeTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ - (void)testPlayerLayerNodeIsNotAddedIfVisibleButShouldNotBePlayingWithUrl
- (void)doPlayerLayerNodeIsNotAddedIfVisibleButShouldNotBePlaying
{
[_videoNode pause];
[_videoNode layer];
[_videoNode setInterfaceState:ASInterfaceStateVisible | ASInterfaceStateDisplay];
[_videoNode didLoad];


XCTAssert(![_videoNode.subnodes containsObject:_videoNode.playerNode]);
}

Expand All @@ -226,7 +226,8 @@ - (void)doVideoStartsPlayingOnDidDidBecomeVisibleWhenShouldAutoplay
return playerLayer;
}];
_videoNode.playerNode.layer.frame = CGRectZero;


[_videoNode layer];
[_videoNode didEnterVisibleState];

XCTAssertTrue(_videoNode.shouldBePlaying);
Expand Down Expand Up @@ -304,7 +305,7 @@ - (void)testVideoThatDoesNotAutorepeatsShouldPauseOnPlaybackEnd
_videoNode.asset = assetMock;
_videoNode.shouldAutorepeat = NO;

[_videoNode didLoad];
[_videoNode layer];
[_videoNode setInterfaceState:ASInterfaceStateVisible | ASInterfaceStateDisplay | ASInterfaceStatePreload];
[_videoNode prepareToPlayAsset:assetMock withKeys:_requestedKeys];
[_videoNode play];
Expand All @@ -325,7 +326,7 @@ - (void)testVideoThatAutorepeatsShouldRepeatOnPlaybackEnd
_videoNode.asset = assetMock;
_videoNode.shouldAutorepeat = YES;

[_videoNode didLoad];
[_videoNode layer];
[_videoNode setInterfaceState:ASInterfaceStateVisible | ASInterfaceStateDisplay | ASInterfaceStatePreload];
[_videoNode prepareToPlayAsset:assetMock withKeys:_requestedKeys];
[_videoNode play];
Expand All @@ -342,6 +343,7 @@ - (void)testVideoResumedWhenBufferIsLikelyToKeepUp

_videoNode.asset = assetMock;

[_videoNode layer];
[_videoNode setInterfaceState:ASInterfaceStateVisible | ASInterfaceStateDisplay | ASInterfaceStatePreload];
[_videoNode prepareToPlayAsset:assetMock withKeys:_requestedKeys];
ASCATransactionQueueWait(nil);
Expand Down

0 comments on commit 8e4932e

Please sign in to comment.