ButtonKit
ButtonKit copied to clipboard
Add isLoading binding to AsyncButton
I often have some kind of editor form with multiple fields and a save button. When the save is loading, I want to disable all the forms in the view. This PR adds an isLoading binding to AsyncButton, so I can easily add .disabled(isLoading) to any view I want. Not sure if this is exactly the best way to implement it, open to feedback!
Hi!
Thanks for your proposal!
The problem with binding is that it implies that you can input manually from the outside. But that's not true. Setting isLoading outside of the button is possible, but makes no sense.
I think the following approach would work for you:
- have your own isLoading as a state
- set that state using the task event modifier already available:
AsyncButton {
...
}
.asyncButtonTaskStarted { task in
// Task started
}
.asyncButtonTaskEnded {
// Task ended or was cancelled
}