Docs
Controls

Commit Button

An async action button in liquid glass that runs through loading, success and error, with a progress bubble budding out of its end.

$npx swiftpieces add CommitButton
Try it in the Playground Use it on a real screen, take it apart, remix it, and copy the SwiftUI. No account needed.
Free · MIT + Commons ClauseiOS 17.0+Liquid Glassbuttonloadingsuccesserrorasynchaptics
Type
CommitButton
Files
CommitButton.swift
Depends on
Nothing (Apple frameworks only)
Version
2.3.1
In a full screen · SwiftPieces ProSend MoneyA transfer review with the recipient, a huge amount and a slide-to-send control that commits with a haptic.

Liquid glass async action button whose whole lifecycle is one bound phase. The capsule is glass, tinted for what it says: signal to act, sage once the work is done, butter on an error. While the work runs a glass bubble buds out of the capsule's end carrying the progress ring, joined to it by a liquid neck, and melts back in once the outcome has landed; on an error it stays out as the retry. The label morphs letter by letter from one message to the next.

Notes

  • phase is a Binding so the button can return itself to .idle after the success hold (successHold, default 900ms); everything else is set by you: .loading in the action, .success or .error("message") when the work finishes.
  • The button is liquid glass. Idle, it is a signal-tinted glass capsule with dark ink; pressed it sinks and the glass darkens a touch. Loading draws the capsule in around its label and buds a round glass bubble out of its end, joined to it by a liquid neck, carrying a signal arc that winds up from rest. Success lets the arc coast to rest as it closes into a ring while the capsule and the bubble turn sage, draws the check and pops it on the success haptic; then, if you pass successTitle ("Saved"), the bubble melts back into the capsule's end as the capsule opens to full width and the label morphs letter by letter into the title, a check beside it. Without a title the check stays in its bubble until the hold ends. An error opens the capsule back out on butter glass, morphs the label into the message, turns the bubble into a butter retry and shakes with the error haptic on the same beat. Disabled is clear glass with muted ink.
  • A new title or successTitle reaches the label as soon as it changes, morphing letter by letter, so a checkout's "Pay $64.00" can follow its total. It never restarts the work, the outcome or the hold, and an error keeps showing its message until the next try.
  • The label gets the capsule's width and no more: the room you give the button, less the bubble while it is out. A label too long for one line there (a long error, an accessibility text size, a narrow screen) wraps onto a second line, shrinking a little if it must, and the capsule grows taller to hold it instead of wider. It never runs past the screen's edge, with collapses on or off.
  • Tapping in the error state, on the label or on the retry bubble, fires the action again (VoiceOver hears "Double tap to try again"). The button ignores taps while loading or succeeding without dimming.
  • collapses: false keeps the capsule full width while it works and makes room for the bubble at its end instead of drawing in around the label.
  • tint and errorTint still work: they override the style's glass tints and switch that state's ink to white. For full control pass a Style with your own tints, ink, height and font. disabledFill no longer does anything: a disabled button is clear glass.
  • Motion uses the shared SwiftPieces springs: the capsule's width, tint and label change together and land with a small give, the bubble leaves on the bud's split spring and goes home with no bounce, its tint draining as it melts in, and only the mark pops. Under Reduce Motion the press darkens instead of sinking, the bubble fades in and out in place, the arc holds still and breathes in opacity while it works, labels cross-fade, and there is no pop or shake; colors, the check, the message and every haptic stay. Reduce Transparency draws the glass solid.
  • Need a slide-to-act confirmation with an amount and recipient? SwiftPieces Pro has the Send Money screen (swipe-to-confirm).

Usage

CommitButtonExample().preferredColorScheme(.light)

Parameters

ParameterDescription
titleIdle label.
phaseBound .idle, .loading, .success, .error(message) or .disabled. The button returns itself to .idle after a success hold.
tintOverrides the style's glass tint while idle and loading, with white ink. nil uses style.fill.
tintInkThe ink on tint, for a tint white doesn't read on (an app's accent and its ink). nil is white.
errorTintOverrides the style's error tint, with white ink. nil uses style.errorFill.
successHoldHow long the success state stays before the button returns to idle.
successTitleText the label morphs to on success, such as "Saved", with a check beside it. nil keeps the check in its bubble until the hold ends.
collapsesDraws the capsule in around its label while it works (the default), so the ring bubble buds out beside it. false keeps the capsule full width and makes room for the bubble at its end.
styleTints, ink, height and type. .standard is the house palette: signal, sage for success, butter for errors.
actionTap handler. Set phase to .loading inside it and to .success or .error when the work finishes.

Install

Pick one. Run it from the folder that contains your .xcodeproj and the files land inside your app.

Terminal

$npx swiftpieces add CommitButton

Or ask your coding agent · Claude Code, Cursor or Xcode, once the MCP server is connected

>Add the SwiftPieces "Commit Button" piece to my app

Or copy the source above into your app.

New to SwiftUI?If you know React, CSS or Tailwind, SwiftUI is easier to pick up than it looks.Try real app patterns first

Building a whole app? See SwiftPieces Pro →

All buttons and controls →

Build it yourself: SwiftUI motion guide · SwiftUI buttons guide · SwiftUI haptics guide

On this page

SwiftPiecesPro

Build the whole app with one library.

Production-ready screens, whole flows, complete app templates, a Build Kit your agent follows and Pro remixing.

54 screens · 46 patterns · 48 flows · 12 templates · 31 Build Kit skills

Explore Pro