Skip to content

scrollPosition(id: Binding<(any Hashable)?>) for lazy containers#346

Merged
marcprux merged 1 commit intoskiptools:mainfrom
dfabulich:scroll-position
Mar 7, 2026
Merged

scrollPosition(id: Binding<(any Hashable)?>) for lazy containers#346
marcprux merged 1 commit intoskiptools:mainfrom
dfabulich:scroll-position

Conversation

@dfabulich
Copy link
Contributor

@dfabulich dfabulich commented Mar 3, 2026

scrollPosition is a pretty complicated feature. You can bind it to the ID of the selected iterable with scrollPosition(id: Binding<(any Hashable)?>), or you can bind it to a ScrollPosition with a bunch of features. In addition, you can pass it a UnitPoint anchor:, allowing you to select which part of the selected item has to be in view.

It would be quite complicated to implement it for all types of containers, but there's a relatively straightforward implementation possible in lazy containers, which have a firstVisibleItemIndex that we can use to convert into a ScrollPositionPreferenceKey.

This implementation doesn't support anchor:, and it doesn't support ScrollPosition; it just tells you the ID of the item scrolled into view. This all that I needed it for, to implement little dots as scroll indicators on a carousel.

Skip Pull Request Checklist:

  • REQUIRED: I have signed the Contributor Agreement
  • REQUIRED: I have tested my change locally with swift test
  • OPTIONAL: I have tested my change on an iOS simulator or device
  • OPTIONAL: I have tested my change on an Android emulator or device
  • REQUIRED: I have checked whether this change requires a corresponding update in the Skip Fuse UI repository (link related PR if applicable)
  • OPTIONAL: I have added an example of any UI changes in the Showcase sample app
    scrollPosition playground skipapp-showcase#67

  • AI was used to generate or assist with generating this PR. Please specify below how you used AI to help you, and what steps you have taken to manually verify the changes.

I used Cursor Kimi 2.5 to generate most of this, testing it with the showcase app.


@marcprux
Copy link
Member

marcprux commented Mar 7, 2026

This looks very useful! Thanks!

@marcprux marcprux merged commit 2ac77e6 into skiptools:main Mar 7, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants