Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

[ASDisplayNode] Trigger a layout pass whenever a node enters preload state #3263

Merged

Conversation

nguyenhuy
Copy link
Contributor

@nguyenhuy nguyenhuy commented Apr 12, 2017

This ensures all subnodes have the correct size to preload their content. This is important for image nodes, as well as collection and table nodes.

For collection node, we can take a step further by telling it load initial data during preload state. Without doing this, the node often loads when it enters display state which is too late. And its cells can't even start prefetching before the loading finishes. Here is a video on pin-to-pin swiping before (left) and after (right) this diff.

Since ASDisplayNode currently doesn't have a layoutIfNeeded implementation, I'd have to allocate its view/layer (or call __layout directly) in order to trigger a layout pass. Instead, I went ahead and implement the method. It's more convenient for users and helps them to avoid prematurely allocate the backing store.

I also took the opportunity to revisit the locking situation of some methods inside ASDisplayNode+UIViewBridge.

@nguyenhuy nguyenhuy force-pushed the HNBetterPreloadStateIntegration branch from 2dbcfbd to 644bbc3 Compare April 12, 2017 19:18
{
[super didEnterDisplayState];
// Since an initial data load was triggered when this node enter preloads state, wait for it to finish
[self waitUntilAllUpdatesAreCommitted];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the scariest part of the change, @Adlai-Holler can you double check that this makes sense to you as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we don't need to do this so I removed it!

@Adlai-Holler Adlai-Holler merged commit dcf858e into facebookarchive:master Apr 13, 2017
bernieperez pushed a commit to AtomTickets/AsyncDisplayKit that referenced this pull request Apr 25, 2018
…state (facebookarchive#3263)

* Add a thread-safe layoutIfNeeded implementation to ASDisplayNode

* Trigger a layout pass when a display node enters preload state
- This ensures that all the subnodes have the correct size to preload their content.

* ASCollectionNode to trigger its initial data load when it enters preload state

* Minor change in _ASCollectionViewCell

* Layout sublayouts before dispatch to main for subclass hooks

* Update comments

* Don't wait until updates are committed when the collection node enters display state

* Same deal for table node

* Explain the layout trigger in ASDisplayNode
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants