Skip to content

Bk/refactor model state batch updates#145

Merged
bryankeller merged 2 commits intomasterfrom
bk/refactor-model-state-batch-updates
Oct 30, 2025
Merged

Bk/refactor model state batch updates#145
bryankeller merged 2 commits intomasterfrom
bk/refactor-model-state-batch-updates

Conversation

@bryankeller
Copy link
Contributor

Details

This refactors how MagazineLayout tracks layout state when batch updates are happening. Previously, the ModelState would store the current and previous section + item models. Many of the ModelState's functions took a BatchUpdateStage parameter, allowing MagazineLayout to ask for layout information for the .beforeUpdates and .afterUpdates stage.

Rather than complicating all of these functions and having them handle the before and after updates stage, we can simply make a copy of the entire ModelState when batch updates occur, and store it as modelStateBeforeBatchUpdates. This simplifies the signatures and implementations of many functions in the ModelState, as they only need to operate on the section and item models that they know about.

This also bumps the minimum iOS version to iOS 12, allowing us to remove some workarounds.

This is the first major step toward tracking a full layout "snapshot" when batch updates occur, which will simplify target-content-offset-related logic, and some other layout-metric-related logic as well. I created a prototype layout to test some of these ideas, and since they proved successful, I'm bring these ideas over to MagazineLayout.

How Has This Been Tested

  • All unit tests pass without modifying their logic.
  • Example app works correctly
  • No obvious regressions in 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 enhancement New feature or request label Oct 30, 2025
inSectionAtIndex: indexPath.section)
else {
// On iOS 9, `layoutAttributesForItem(at:)` can be invoked for an index path of a new item
// before the layout is notified of this new item (through either `prepare` or
Copy link
Contributor

Choose a reason for hiding this comment

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

should we go ahead and clean up these comments referencing unsupported versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yeah, good idea, I can remove the comment in the next PR

Copy link
Contributor

@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.

much nicer!

@bryankeller bryankeller merged commit 545707d into master Oct 30, 2025
1 check passed
@bryankeller bryankeller deleted the bk/refactor-model-state-batch-updates branch October 30, 2025 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants