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

Avoid reset of containers when anchor element is replaced in ItemsRepeater #926

Merged
merged 2 commits into from
Jun 25, 2019

Conversation

ranjeshj
Copy link
Contributor

@ranjeshj ranjeshj commented Jun 22, 2019

Currently replace is modeled as a remove and an add, but unfortunately if the remove ends up removing the anchor element, then during next measure we think we are disconnected and throw all the containers away and start from scratch. This causes a flash of all the images which is undesirable. With this change, if we are doing a replace in the realized range, then we can just clear those items and set the containers as null (sentinels). We already look for sentinels during the measure pass and realize them as needed. This will ensure that only the replaced containers will get cleared/prepared again.

Fixes #915
Fixes #935

@ranjeshj ranjeshj requested review from micahl, jlaanstra and a team June 22, 2019 04:43
@jevansaks jevansaks added the release note PR that we want to call out in the next release summary label Jun 22, 2019
Copy link
Member

@kmahone kmahone left a comment

Choose a reason for hiding this comment

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

:shipit:

@ranjeshj ranjeshj merged commit e45e83d into master Jun 25, 2019
@msft-github-bot
Copy link
Collaborator

🎉Microsoft.UI.Xaml v2.2.190702001-prerelease has been released which incorporates this pull request.:tada:

Handy links:

{
if (m_flowAlgorithm.GetElementIfRealized(0))
if (m_cachedFirstElement != nullptr && m_flowAlgorithm.GetElementIfRealized(0))
Copy link

Choose a reason for hiding this comment

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

Can this check ever pass? On this line if m_cachedElement is successfully added to m_flowAlgorithm then m_cachedElement is set to nullptr.

So the way I read it, is that m_cachedFirstElement != nullptr OR m_flowAlgorithm.GetElementIfRealized(0) can be true, but not both together. Or am I missing something?

Copy link
Contributor Author

@ranjeshj ranjeshj Jul 5, 2019

Choose a reason for hiding this comment

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

We do not want to recycle if just m_cachedFirstElement is not nullptr. That would mean that every layout pass we will throw away the element only to realize it in the next pass. This cache is trying to avoid it. This is making sure that if we created element0 in the state, but the algorithm created one too, then we can let the one state created go away. Otherwise we just keep the cached element. This is a bit twisted unfortunately because we are reusing the algorithm for stack/grid and flow layouts and grid has the special behavior based on the first element.

Copy link

Choose a reason for hiding this comment

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

Thanks @ranjeshj. That makes sense, I think what confused me was the comment "flowlayout algorithm took ownership", which suggested to me that this was supposed to tidy up the element transferred to the flow layout on line 62. 👍

{
// We created the element, but then flowlayout algorithm took ownership, so we can clear it and
// let flowlayout algorithm do its thing.
context.RecycleElement(m_cachedFirstElement);
Copy link

Choose a reason for hiding this comment

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

This doesn't handle the case where we created the element, but then flowlayout didn't take ownership, in which case the element still needs to be recycled IIUC?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We want to keep it cached (and not recycle) in that case to use for the next pass.

@anawishnoff anawishnoff deleted the user/ranjeshj/replaceitems branch November 3, 2020 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release note PR that we want to call out in the next release summary
Projects
None yet
7 participants