Add GeometryReader#56
Merged
Merged
Conversation
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.
GeometryReader { geometry in … }, giving views access to the space they're offered. This was the deepest of the remaining gaps because it's the one place data has to flow backwards: Swift resolves a tree before Compose lays it out, so the node tree had no size-feedback path at all.How it works, and why it terminates
The interpreter measures, reports the size through a string callback, and the resulting store update re-evaluates with real numbers — so a GeometryReader settles over two passes (zero on the first, measured on the second). No new bridge entry point: the size rides the existing string callback as
"<width>,<height>".Two properties keep that from becoming an infinite layout loop, and both are deliberate:
An unbounded height (inside a scrolling parent) isn't a real offer, so it reports
0for that axis rather than infinity; give the reader an explicit.frame(height:)there.Verification
swift test— 89 total passing. One test walks the two-pass settling end to end (content readsw=0 h=0, thenw=320 h=240after a report). The other drives the size store directly to pin the settling rule — a new size re-evaluates, the same size does not, a later change does again, and malformed reports never do. That second test is the one guarding against a re-evaluation loop.360 × 200, and bars drawn atsize.width / 2and/ 4measure exactly half and a quarter of the reader — the number is load-bearing, not just displayed. Toggling the frame re-measures in both directions (200 → 320 → 200) and settles each time.Scope
GeometryProxyexposessizeonly —frame(in:),safeAreaInsets, and named coordinate spaces aren't modeled, and there's no.coordinateSpace. Worth knowing that a GeometryReader costs an extra evaluation pass whenever its size changes.