Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assert node did load before did enter visible way 1 #886

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
929d118
fix SIMULATE_WEB_RESPONSE not imported #449
wsdwsd0829 Jul 16, 2017
dd24d8f
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Sep 6, 2017
b8eaffa
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Oct 4, 2017
2918ea0
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Oct 11, 2017
9c42266
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Oct 12, 2017
329f35f
Fix to make rangeMode update in right time
wsdwsd0829 Feb 5, 2018
5f8b7ec
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Feb 7, 2018
d87bb11
merge master from upstream
wsdwsd0829 Feb 15, 2018
269c2ab
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Mar 10, 2018
24c1ce8
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Mar 12, 2018
233169e
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Mar 26, 2018
b19f90d
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Mar 28, 2018
b50cec4
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 Apr 5, 2018
af8af43
access layer to load node before enter visible
wsdwsd0829 Apr 18, 2018
94c2b63
Merge branch 'master' into assert-nodeDidLoad-before-didEnterVisible-1
wsdwsd0829 Oct 15, 2018
a82339a
merge master.
wsdwsd0829 Oct 17, 2018
fc08822
merge
wsdwsd0829 Oct 17, 2018
1257817
Merge branch 'master' into assert-nodeDidLoad-before-didEnterVisible-1
wsdwsd0829 Oct 22, 2018
ccb3abf
Merge branch 'master' of github.com:TextureGroup/Texture into assert-…
wsdwsd0829 Oct 23, 2018
179b17d
revert space
wsdwsd0829 Oct 23, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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