Repository navigation
Keep a fixed-size view from taking its stack's free space on the fixed axis - #585
Merged
Merged
Conversation
…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).
Member
|
Good catch! |
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.
Follow-up to #561. With that fix a vertical
ScrollViewunder.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.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'sComposeContainercallsflexibleHeight(max: .flexibleFill), which goes through the_flexibleHeightclosure the parent stack puts in the environment. That marks the scroll view as filling, so theVStackgives it the leftover space.fixedSize'swrapContentHeight(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:
LayoutTests.testFixedSizeVerticalScrollViewInStackLeavesFreeHeightToSpacerputs a fixed-sizeScrollView(4x4 content), a white 8x2 bar and aSpacer(minLength: 0)in aVStackinside a 12x12 frame. The bar's position shows the scroll view's height: SwiftUI draws it directly under the content.fixedSize(horizontal:vertical:)renders its content with_flexibleWidthcleared whenhorizontalis true and_flexibleHeightcleared whenverticalis true, usingEnvironmentValues.shared.setValuesthe wayallowsHitTestingdoes. On a fixed axis the content no longer tells its parent it wants to fill, andflexibleHeight(max: .flexibleFill)falls back tofillMaxHeight(), which has no effect underwrapContentHeight(unbounded = true). The scroll view takes its content's height and the stack gives the free space to itsSpacer, as in SwiftUI.This also changes other flexible views placed directly under
fixedSizeon the fixed axis (Spacer,Color,.frame(maxHeight: .infinity)): they no longer fill there, which matches SwiftUI, wherefixedSizeproposes no size on that axis. The non-fixed axis is untouched, and a view nested inside another container is unaffected because eachComposeContainersets its own flexible closures for its children.Evidence
Unit tests,
swift teston this branch (mainat0e0c0ba), macOS 27 / Xcode 27.1: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
fixedSizebefore 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-sizeScrollViewabove. Only theScrollViewscreen changed, and it now matches the same screen on an iOS simulator.