Repository navigation
Feature/scroll position with geometry - #573
Open
gurmeherchawla wants to merge 6 commits into
Open
gurmeherchawla wants to merge 6 commits into
gurmeherchawla wants to merge 6 commits into
Conversation
This fixes a bug where, after the first withAnimation, every later change kept animating on Android
Adds support for ScrollPosition, onScrollGeometryChange and onScrollPhaseChange.
Adds ScrollPosition, scroll geometry, and scroll phase support
Adds document for scroll position, geometry and phase support
Take upstream's List.swift section rendering (skiptools#583) and re-apply this branch's clearScrollContainerValues wrapper around the LazyColumn. Combine upstream's idealSizeOnUnboundedScrollAxes with the ScrollViewDriver size tracking in ScrollView.swift. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Support ScrollPosition, onScrollGeometryChange, and onScrollPhaseChange
Adds Android support for programmatic scrolling with
ScrollPosition, makes.scrollPosition(id:anchor:)two-way, addsScrollViewProxyanchors, and bringsonScrollGeometryChangeandonScrollPhaseChangeto every scroll container. Thebehavior follows iOS 26, which I checked case by case on the simulator.
Related PR: #532
What changes
ScrollPosition
ScrollPositionwas an unavailable stub. It's now a value type with every iOS initializer, thescrollTo(id:anchor:),scrollTo(edge:),scrollTo(point:), andscrollTo(x:y:)variants, andedge,point,viewID,viewID(type:),and
isPositionedByUser..scrollPosition(_:anchor:)scrolls as the binding changes, animated insidewithAnimation..scrollPosition(id:anchor:)used to only report the top item. It now also scrolls when the ID changes, and supportsanchor.Matching iOS
ScrollPosition(id:)for the first view whose middle is past the anchor, and leavesisPositionedByUserfalse (what iOS 26 does). Views without IDs write nothing.pointis nil unless both x and y were set.ScrollViewReader:
scrollTo(_:anchor:)honorsanchor, and works on the.id/ForEachviews of a non-lazyScrollView, which it didn't before.Geometry:
ScrollGeometryand.onScrollGeometryChangework inScrollView, the lazy stacks and grids, andList.Phase: both
.onScrollPhaseChangeoverloads report:idle → idleonceidle → interacting → idleinteracting → decelerating → idledeceleratingidle → animating → idleBug fix: the
withAnimationmarker read byAnimation.isInWithAnimationwas never cleared, because its coroutine ranon
Dispatchers.Main, which has no frame clock. Every change after the firstwithAnimationthen animated. It's aseparate commit.
How it works
ScrollPosition.swiftadds aScrollDriverprotocol with two implementations:ScrollViewDriver:ScrollState, plus the layout coordinates that.id/ForEachviews register as they're placed.LazyScrollDriver:LazyListState/LazyGridState, plusLazyItemCollector.ScrollDriverEffectsconnects a driver to the reader, position, geometry, and phase APIs. Each container replaces itsown scroll-to-ID and position code with about three lines.
snapshotFlowin effects, never read during composition, so updates don'trecompose the container. On a device, a
LazyVStackwith.scrollPosition(id:)scrolls with the same jank as onewithout it.
Notes for review
List.swift: theLazyColumnis wrapped in an environment scope and re-indented. The diff is 9 lines added and 12removed with whitespace ignored.
visible items' average size; they're exact for uniform rows.
contentInsetsis zero.CGVector, soScrollEffects.swiftadds a minimal Kotlin-only one forScrollPhaseChangeContext.velocity.unusedp:parameter onscrollPosition(_:anchor:), because erasure gives bothscrollPositionoverloads the sameJVM signature.
Binding<out Hashable?>declaration onscrollPosition(id:), so$positionresolves to theScrollPositionoverload.
suspenddeclarations on the driver methods, which run Compose scroll calls in effect coroutines.Skip Pull Request Checklist:
swift test