Add control styles: button, picker, toggle, text field#55
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.
The style system was the largest remaining parity gap — there was no way to restyle any control. This adds
.buttonStyle,.pickerStyle,.toggleStyle, and.textFieldStyle.The design decision worth reviewing
A style is not a per-node modifier. In SwiftUI
VStack { … }.buttonStyle(.bordered)styles every button in the subtree, so a style has to propagate down. This codebase already had exactly the right mechanism — theCompositionLocalinheritance that carries font, foreground color,disabled, and tint (#38) — so styles ride the same unconditionalCompositionLocalProviderfold inRenderChild. Each control reads its own local.(Provided unconditionally, never behind a branch: conditional provision tears down remembered state in the subtree, the gotcha from the animation work.)
Each control's style is its own modifier
kind(buttonStyle,pickerStyle, …), so styles for different controls compose on one view instead of overwriting each other — covered by a test.Presentations
automatic/borderedProminentfilled,borderedoutlined,plain/borderlesslabel-onlyautomatic/menudropdown,segmenteda real segmented control,inlinea radio listswitch,checkbox,button(a selectable chip)roundedBorder/automaticoutlined,plainwith the box and indicators strippedVerification
swift test— 3 new tests, 87 total passing. The load-bearing one asserts a container carries the style while its buttons carry none of their own, which is what distinguishes inheritance from a per-node modifier..buttonStyle(.bordered)render outlined — inheritance working end to endplaintext field has no box whereroundedBorderdoesScope
Built-in style spellings only — the
ButtonStyle/ToggleStyle/… protocols for authoring custom styles aren't modeled, and.listStyle/.labelStylearen't included.borderedProminentcurrently renders the same asautomatic(both filled), since Material's filled button is already the prominent affordance.