Don't inherit the presenter's scroll axes into a presentation#477
Open
garthvh wants to merge 1 commit into
Open
Don't inherit the presenter's scroll axes into a presentation#477garthvh wants to merge 1 commit into
garthvh wants to merge 1 commit into
Conversation
A sheet (or other presentation) is a new layout root, but PresentationRoot
left the presenter's `_scrollAxes` / `_layoutScrollAxes` in the environment.
When a sheet is presented from inside a ScrollView, expanding content in the
sheet is then sized with `IntrinsicSize.Max` — as if it were laid out in the
presenter's scroll direction (ComposeFlexibleContainer). For a sheet whose
content is a List (or any lazy container) that intrinsic pass crashes:
java.lang.IllegalStateException: Asking for intrinsic measurements of
SubcomposeLayout layouts is not supported.
and, before reaching the lazy content, the intrinsic constraint (maxHeight ==
Constraints.Infinity) also overflows IgnoresSafeAreaLayout's expansion
arithmetic:
java.lang.IllegalArgumentException: maxWidth must be >= than minWidth
Reset both scroll-axis environment values at the presentation boundary so the
sheet lays out from a clean root, and guard IgnoresSafeAreaLayout's expansion
against the Infinity constraint the same way the existing
`constraint(_:subtracting:)` helper does (preserve Infinity, clamp to the
mins) so an intrinsic measurement can never overflow it.
Repro: present a sheet containing a List from a button inside a ScrollView;
it crashes on Android (fine on iOS). Related to skiptools#191.
|
Thank you for your pull request and welcome to the Skip community. We require contributors to sign our contributor license agreement (CLA), and we don't seem to have the user(s) @garthvh on file. In order for us to review and merge your code, for each noted user please add your GitHub username to Skip's .clabot file |
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.
Problem
Presenting a
.sheetwhose content is aList(or any lazy container) from a button inside aScrollViewcrashes on Android. It works fine on iOS.and, on the path before the lazy content is reached, the intrinsic measurement (
maxHeight == Constraints.Infinity) also overflowsIgnoresSafeAreaLayout's expansion arithmetic:Cause
A presentation is a new layout root, but
PresentationRootleft the presenter's_scrollAxes/_layoutScrollAxesin the environment. When the sheet is presented from within aScrollView,ComposeFlexibleContainerthen sizes expanding content in the sheet withModifier.height(IntrinsicSize.Max)— the "fill in a scroll direction" path — as if the sheet were laid out in the presenter's scroll direction. Asking aListfor its intrinsic height is what Compose forbids, hence the crash.Fix
PresentationRoot: reset_layoutScrollAxesand_scrollAxesto empty at the presentation boundary, so the presentation lays out from a clean root and doesn't inherit an intrinsic-sizing regime from whatever presented it.IgnoresSafeAreaLayout: guard the safe-area expansion against anInfinityincoming constraint the same way the existingconstraint(_:subtracting:)helper does (preserveInfinity, clamp to the min constraints), so any intrinsic measurement pass can't overflowIntinto a negativemaxWidth.Reproduce
Present a sheet containing a
Listfrom aButtoninside aScrollView. Crashes on Android before this change; renders and scrolls after.Verification
Built and run on an Android emulator: the sheet (including a sheet-presented-from-a-sheet, and a
Listwith sub-rows) renders, scrolls, and dismisses cleanly. iOS behavior is unchanged. Related to #191, though that report is a genuinely-nested scroll case; this one is scroll-axis inheritance leaking across the presentation boundary.