Repository navigation
fix(zero-swift): lay out a viewport shorter than its insets as an empty one - #276
Merged
Merged
Conversation
…ty one `RowsScrollView` passes `LayoutHost.layout` its height less its content insets. On iOS a scroll view shorter than its safe area's insets (a 90 pt tall window on an iPhone) makes that negative, and `LayoutHost.reach` then built `(offset - viewport)...(offset + 2 * viewport)` with its lower bound above its upper one, which traps: "Range requires lowerBound <= upperBound". macOS's clip view can do the same with its content insets. `layout(offset:viewport:)` now takes a negative viewport as 0, so the host, and the core reading `viewportHeight`, see a viewport with no room for rows. Once the view grows, its rows are measured and drawn as before. The new layout host test starts at a viewport of -40 and grows to 400; on main it traps. A scratch probe hosting `VirtualList` in an 800x90 window on the iOS Simulator (iPhone 17 Pro) trapped before and lays out every case after. Amp-Thread-ID: https://ampcode.com/threads/T-884aab88-be49-4bc7-96a1-044f0e71dabf Co-authored-by: tmm <tmm@tmm.dev>
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.
RowsScrollViewpassesLayoutHost.layoutits height minus its content insets. On iOS, a scroll view shorter than its safe area's insets makes that negative; a 90-pt-tall window on an iPhone is enough.LayoutHost.reachthen built(offset - viewport)...(offset + 2 * viewport)with a lower bound above its upper one, which traps with "Range requires lowerBound <= upperBound". macOS's clip view can get there the same way through its content insets.layout(offset:viewport:)now treats a negative viewport as 0. The host, and the core that readsviewportHeight, see a viewport with no room for rows. Once the view grows, its rows are measured and drawn as before. Viewports of 0 or more take the same path as before.Tests. A new layout host test starts at a viewport of −40, settles, then grows to 400 and checks that the first row is drawn at the top with no blank space. On main it traps (
Swift/ClosedRange.swift:409: Fatal error: Range requires lowerBound <= upperBound); with the fix it passes.End to end. A scratch probe (not committed) hosted
VirtualListin an 800×90 window on the iOS Simulator (iPhone 17 Pro, Xcode 27.3). It trapped inLayoutHost.reachfromRowsScrollView.layoutSubviewsbefore the fix, and lays out all 44 of its cases after.Run locally. Linux:
swift test --filter ZeroVirtualTests(133 tests) andswift format lint --strict. iOS Simulator:xcodebuild test -only-testing:ZeroVirtualTests/LayoutHostTests.Patch changeset.