Skip to content

Keep a fixed-size view from taking its stack's free space on the fixed axis - #585

Merged
fhasse95 merged 2 commits into
skiptools:mainfrom
Aecasorg:fixedsize-flexible-axis
Oct 22, 2026
Merged

fhasse95 merged 2 commits into
skiptools:mainfrom
Aecasorg:fixedsize-flexible-axis

Conversation

@Aecasorg

Copy link
Copy Markdown
Contributor

Follow-up to #561. With that fix a vertical ScrollView under .fixedSize(horizontal: false, vertical: true) no longer crashes, but inside a stack it still takes the stack's free height and centres its content in it. On iOS its frame hugs the content.

VStack(spacing: 16) {
    Button("Show") { }
    ScrollView {
        VStack(alignment: .leading, spacing: 12) {
            ForEach(["Passport", "Driving licence", "Unavailable"], id: \.self) { Text($0) }
        }
    }
    .fixedSize(horizontal: false, vertical: true)
    .border(Color.blue)
    Spacer()
}
iOS 27 Android 17, skip-ui 1.61.0 + #561 Android 17, + this PR

The border runs from under the button to the bottom of the screen, with the three rows centred in it. The horizontal case, ScrollView(.horizontal) with .fixedSize(horizontal: true, vertical: false), already matched iOS.

In a production Skip Fuse app this showed on a proof-of-age screen built as Spacer, heading, Spacer, fixed-size list, Spacer, button, Spacer: the list took all the free height, the spacers collapsed, and the heading sat right under the navigation bar instead of where iOS puts it.

Cause

ScrollView's ComposeContainer calls flexibleHeight(max: .flexibleFill), which goes through the _flexibleHeight closure the parent stack puts in the environment. That marks the scroll view as filling, so the VStack gives it the leftover space. fixedSize's wrapContentHeight(unbounded = true) is on the same node, so the scroll view reports the space it was given and centres its content in it.

Change

Two commits:

  1. Test. LayoutTests.testFixedSizeVerticalScrollViewInStackLeavesFreeHeightToSpacer puts a fixed-size ScrollView (4x4 content), a white 8x2 bar and a Spacer(minLength: 0) in a VStack inside a 12x12 frame. The bar's position shows the scroll view's height: SwiftUI draws it directly under the content.
  2. The fix. fixedSize(horizontal:vertical:) renders its content with _flexibleWidth cleared when horizontal is true and _flexibleHeight cleared when vertical is true, using EnvironmentValues.shared.setValues the way allowsHitTesting does. On a fixed axis the content no longer tells its parent it wants to fill, and flexibleHeight(max: .flexibleFill) falls back to fillMaxHeight(), which has no effect under wrapContentHeight(unbounded = true). The scroll view takes its content's height and the stack gives the free space to its Spacer, as in SwiftUI.

This also changes other flexible views placed directly under fixedSize on the fixed axis (Spacer, Color, .frame(maxHeight: .infinity)): they no longer fill there, which matches SwiftUI, where fixedSize proposes no size on that axis. The non-fixed axis is untouched, and a view nested inside another container is unaffected because each ComposeContainer sets its own flexible closures for its children.

Evidence

Unit tests, swift test on this branch (main at 0e0c0ba), macOS 27 / Xcode 27.1:

macOS (SwiftUI) Robolectric
Commit 1 only (no fix) new test passes new test fails: the scroll view takes 10 of the 12 rows and the bar is pushed to the bottom; 212 tests, 192 passed, 1 failed, 19 skipped
Both commits new test passes 212 tests, 193 passed, 0 failed, 19 skipped

No other test changes result. macOS has one failure in every run, LayoutTests.testDrawTextDefaultFont, the same one noted on #561; it fails without these commits too.

Emulator. Scene 5 of Aecasorg/skip-fuse-perf-repro fixedsize-scrollview (scene source), skip-fuse-ui 1.19.0, Android 17 emulator: the screenshots above. That run used skip-ui 1.61.0 with #561 and these two commits applied, on our fork, which carries a few other unrelated patches.

A production app. We pinned these commits in a Skip Fuse app and compared every screen that uses fixedSize before and after on Android 15, pixel by pixel: fixedSize() on rotated text, fixedSize(horizontal: true, vertical: false) on a capsule label, fixedSize(horizontal: false, vertical: true) on wrapping text, and the fixed-size ScrollView above. Only the ScrollView screen changed, and it now matches the same screen on an iOS simulator.

…to its Spacer

In a VStack with a Spacer, a vertical ScrollView under
.fixedSize(horizontal: false, vertical: true) should be as tall as its
content, as in SwiftUI. On Android it takes the stack's free height and
centres its content in it, so the view below it is pushed to the bottom.
Passes on macOS, fails on Robolectric until the fix.
…d axis

fixedSize now renders its content without the parent's flexible layout
on each fixed axis. A vertical ScrollView under
.fixedSize(horizontal: false, vertical: true) in a VStack used to report
itself as filling, so the stack gave it the free height and its content
sat centred in a frame taller than the content. It is now as tall as its
content, as in SwiftUI, and a Spacer below it takes the free height.

Robolectric: 158 passed, 0 failed (was 157 passed, 1 failed).
@cla-bot cla-bot Bot added the cla-signed label Oct 22, 2026
@fhasse95

Copy link
Copy Markdown
Member

Good catch!

@fhasse95
fhasse95 merged commit 6aa259e into skiptools:main Oct 22, 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