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

Fix target content offset edge case #115

Merged
merged 1 commit into from
Jan 18, 2024

Conversation

bryankeller
Copy link
Contributor

@bryankeller bryankeller commented Jan 18, 2024

Details

This fixes an issue that could cause the target content offset to be computed with incorrect layout metrics (bounds / content size / content insets) when the collection view is first appearing. This can happen if there are some forced layout passes due to navigation bars being sized, for example.

The general issue is that prepareForAnimatedBoundsChange is called with an oldBounds value, but we have no idea what the content inset / content size of the collection view was when that was our current bounds. If we use updated content inset / content size values, but with the previous bounds value, then we'll compute an incorrect target content offset. To make matters worse, there's no exact order of layout lifecycle calls that we can depend on to save our previous inset / bounds. To work around this, we need to store a few bounds + content inset + content size states, which we can later reference in prepareForAnimatedBoundsChange so that we can use the right values.

Previously, we just stored the last values seen in invalidateLayout, rather than the last 3. This isn't good enough, since invalidateLayout will be called many times with differing values, but the values that we actually have access to in prepareForAnimatedBoundsChange might need to be from a few invalidations in the past. What a pain.

Related Issue

N/A

Motivation and Context

Fix internal Airbnb issue

How Has This Been Tested

Example app, Airbnb app

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

@bryankeller bryankeller added the bug Something isn't working label Jan 18, 2024
@bryankeller bryankeller force-pushed the bk/fix-target-content-offset-edge-case branch from 8b437ff to a732f7d Compare January 18, 2024 07:38
Copy link

@brynbodayle brynbodayle left a comment

Choose a reason for hiding this comment

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

Ugh, those early layout passes really break a lot of assumptions.

@bryankeller bryankeller merged commit c3f346b into master Jan 18, 2024
2 checks passed
@bryankeller bryankeller deleted the bk/fix-target-content-offset-edge-case branch January 18, 2024 18:20
bryankeller added a commit that referenced this pull request Feb 9, 2024
bryankeller added a commit that referenced this pull request Feb 13, 2024
* Revert "Fix target content offset edge case (#115)"

This reverts commit c3f346b.

* Sort element location frame pairs

* Improve logic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants