Merged
Conversation
51318cb to
6f73658
Compare
maxg-square
reviewed
Jun 2, 2025
maxg-square
reviewed
Jun 2, 2025
maxg-square
reviewed
Jun 2, 2025
maxg-square
approved these changes
Jun 2, 2025
johnnewman-square
approved these changes
Jun 3, 2025
g-mark
approved these changes
Jun 3, 2025
| @@ -0,0 +1,18 @@ | |||
| /// A protocol for layouts that have a single associated trait type. | |||
| /// | |||
| /// Legacy layout implementations can implement this protocol to easily apply and read their traits | |||
Contributor
There was a problem hiding this comment.
This is a neat way to support legacy layouts - and looks like it's also handy for some non legacy ones!
Just out of curiosity, would it also work if LayoutTraitsKey conformance were added to the legacy layout (and flow, gridRow, etc.) instead of SingleTraitLayout? The defaultValue might be awkward (but could be renamed to defaultTraitValue or something), or isn't the api you're going for.
Collaborator
Author
There was a problem hiding this comment.
Yep, other than the slight API mismatch, you could accomplish the same thing that way. I think there's some good semantic info conveyed by SingleTraitLayout though, and storing the SingleTraitLayout key separately from new standalone keys feels nice.
robmaceachern
approved these changes
Jun 4, 2025
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.
This PR adds keyed layout traits that work similarly to SwiftUI's LayoutValueKey. You can define keys in the style of Environment keys, and then read the values off subelements during layout.
To support legacy layout implementations, the
SingleTraitLayoutprotocol provides the existing API. When legacy layout is removed, layouts that have an associated trait type only need to conform to this protocol to keep working as-is.Decoupling the legacy
Traitstype from theLayoutprotocol will allow us to remove theLegacyLayoutrequirements cleanly. I'll do that in a follow-up.