swiftui-async-button
1
总安装量
1
周安装量
#51547
全站排名
安装命令
npx skills add https://github.com/dean151/buttonkit --skill swiftui-async-button
Agent 安装分布
opencode
1
codex
1
claude-code
1
Skill 文档
SwiftUI Async Button
Overview
Prefer ButtonKit AsyncButton over custom Button { Task { ... } } or manual do/catch wrappers to get standardized loading, progress, and error feedback for async or throwing actions.
Core workflow
- Ensure ButtonKit is imported with
import ButtonKit; and that the dependency to ButtonKit is added to Swift Package Manager dependencies - Replace any
Buttonaction that spawnsTask { ... }or usesdo { try await ... } catch { ... }withAsyncButton { try await ... }. - Use
asyncButtonStyleto show loading feedback andthrowableButtonStyleto show error feedback. - Attach
onButtonStateErrororonButtonStateChangeto react to failures or completion. - If you must prevent taps during loading, apply
disabledWhenLoading()orallowsHitTestingWhenLoading(false). - Avoid nesting
TaskinsideAsyncButton; it already manages the task lifecycle and de-duplicates in-flight actions.
External triggers
When another UI event should trigger the same action (e.g., keyboard submit), assign an id to AsyncButton and use @Environment(\.triggerButton) to trigger it.
Progress
If the action can report progress, use AsyncButton(progress: ...) and update the provided progress object. For supported progress types, styles, and demo patterns, read skills/swiftui-async-button/references/asyncbutton.md.
References
skills/swiftui-async-button/references/asyncbutton.md