Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decompose Button-like components to separate parts #605

Open
PavelHolec opened this issue Jun 22, 2023 · 0 comments
Open

Decompose Button-like components to separate parts #605

PavelHolec opened this issue Jun 22, 2023 · 0 comments
Labels
enhancement New feature or request maintenance

Comments

@PavelHolec
Copy link
Collaborator

PavelHolec commented Jun 22, 2023

Components could be decomposed to separate public parts for better reusability and flexibility. We would still keep the convenience standalone component, but it would be a thin wrapper over its FooButtonStyle + FooContent implementation.

Add internal environmentKey for buttonPressed(Bool) to be able to snapshot and preview active button states.

For example, ListChoice would be restructured into:

  • Convenience component wrapper ListChoice(…), as-is
  • Content component ListChoiceContent that defines the layout itself (plus accessibility)
  • A ButtonStyle ListChoiceButtonStyle that takes care of proper isPressed and similar interaction (keeping title as a Button Label to provide label accessibility automatically)

This way, such components could be structured as:

ListChoice(...)

==

SwiftUI.Button(...) {
  ListChoiceContent(..)
}
.buttonStyle(ListChoiceButtonStyle(..))

Limitation

In SwiftUI, a ButtonStyle definition cannot be specified using other (more generic, for example) .buttonStyle()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request maintenance
Projects
None yet
Development

No branches or pull requests

1 participant