Files
claude-plugins/pdat-swift-practice/skills/apple-findings/references/scrolling.md
T
TomUviandClaude Opus 5 f84852d49c Collect findings from other people's writing, with sources
The skill so far only held what we broke ourselves. Most of what is worth
knowing about a new SDK is found rather than suffered — release notes,
other people's articles — and that deserves a place too, on terms that
stay fair to whoever wrote it.

So: entries in our own words, source named and linked, and the one thing
no external article can supply — what it would replace in our code and
whether it is genuinely a step forward. Attribution answers plagiarism,
not copyright, so nothing is pasted; an API signature is a fact, the
paragraph explaining it is not ours to take.

First four entries come from Natalia Panferova's writing at nilcoalescing
.com: the close button role and concentric corners, both of which replace
things we hand-built; ScrollPosition, which replaces one wrapper view;
and the iOS 27 toolbar APIs, which we cannot use at our deployment target
but which would delete a workaround the day we can.

A LICENSE was overdue and now says plainly what is ours, what is Apple's
and stays out of the repository, and what belongs to the authors we cite.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-16 23:14:51 +02:00

37 lines
1.4 KiB
Markdown

# Programmatic scrolling
## `ScrollPosition` instead of `ScrollViewReader`
**What it is.** A `ScrollPosition` value held in `@State` and attached with
`.scrollPosition($position)` replaces wrapping content in a
`ScrollViewReader` to get at a proxy. Scrolling is then a method call on
the state — `position.scrollTo(id:)` — and, unlike the proxy, the value
can also be read, so the position is available both ways.
```swift
@State private var position = ScrollPosition()
ScrollView(.horizontal) {
HStack { ForEach(items) { ItemView(item: $0).id($0.id) } }
}
.scrollPosition($position)
```
Related, same family: `.defaultScrollAnchor(.bottom)` for where a view
starts out, and `onScrollGeometryChange(for:of:action:)` (iOS 18) for
following the offset while the user drags.
**What it replaces.** A `ScrollViewReader` wrapped around content purely
to reach `proxy.scrollTo` from a `.task`. In our card list that is the
filter chip strip, which scrolls the active chip into view.
**Step forward?** Modest but real. One layer of nesting disappears and the
scroll position stops being write-only. Not urgent — the existing code
works — so worth doing when that view is touched for another reason.
**Available since.** iOS 17, so nothing blocks it at our deployment
target. `onScrollGeometryChange` needs iOS 18.
**Source.** Natalia Panferova, "Modern SwiftUI APIs for programmatic
scrolling", nilcoalescing.com, 19 May 2026. Read 16 Aug 2026.