https://github.com/fluidgroup/buttonstylemodifier
An easier way to make a button style with closure or passing an instance of ViewModifier.
https://github.com/fluidgroup/buttonstylemodifier
button swiftui
Last synced: 2 months ago
JSON representation
An easier way to make a button style with closure or passing an instance of ViewModifier.
- Host: GitHub
- URL: https://github.com/fluidgroup/buttonstylemodifier
- Owner: FluidGroup
- Created: 2024-11-28T12:01:42.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-28T15:26:54.000Z (over 1 year ago)
- Last Synced: 2025-03-26T15:16:56.533Z (over 1 year ago)
- Topics: button, swiftui
- Language: Swift
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
An easier way to make a button style with closure or passing an instance of `ViewModifier`.
```swift
Button("Button") {
print("")
}
.buttonStyle(
ButtonStyleModifier { label, state in
label
.padding()
.background(
RoundedRectangle(cornerRadius: .infinity, style: .continuous)
.foregroundColor(Color.secondary)
)
.opacity(state.isEnabled ? 1 : 0.3)
}
```
`ButtonStyleModifier` supports indicating state of processing by `.processing()` modifier.
This state can be read from state parameter in ButtonStyleModifier.
ButtonStyleModifier sets the following environment values for making styles in ViewModifier.
```swift
extension EnvironmentValues {
@Entry public var _styled_isPressed: Bool = false
@Entry public var _styled_isProcessing: Bool = false
}
```