Twitter Github Get Early Access
Action Button
Replacement Button
featuring built-in .enabled
, .disabled
, and .loading
states. Plus a small tap animation on top of it all.
Replacement Button
featuring built-in .enabled
, .disabled
, and .loading
states. Plus a small tap animation on top of it all.
How to Use
Step 1:
Install with Swift Package Manager. In your Xcode Project, select File > Add Packages, and paste in the following URL:
https://github.com/swiftui-library/action-button
Step 2:
Import ActionButton
, create a State variable or binding of type ActionButtonState
. This will drive the view.
Next, add ActionButton
to your view and configure it. Here's an example.
@State var actionButtonState: ActionButtonState =
.enabled(.init(title: "Load Something", systemImage: "bolt"))
var body: some View {
VStack {
Text("Just a little button.")
ActionButton(state: $actionButtonState, onTap: {
loadSomething()
}, backgroundColor: .red)
.frame(maxWidth: 250)
}
}
Animating between states.
Animating between states is handled automatically. Take a look at the loadSomething()
function.
private func loadSomething() {
actionButtonState = .loading(.init(title: "Loading", systemImage: "bolt"))
DispatchQueue.main.asyncAfter(deadline: .now() + 1.25) {
actionButtonState = .disabled(.init(title: "Loaded", systemImage: "checkmark"))
}
}
Configuration
For more details about configuration, visit the Github repo. This will always have the most up to date information.