Confirm morph
Centered split, second-tap and hold confirmation with colored countdown outlines, asynchronous feedback and timed Undo.
npx @swipeui/cli add confirm-morphWhen to use it
- Delete, remove or archive actions that should ask "Are you sure?" right in place, without a dialog.
- Actions that run on a server and need visible pending, success and failure states.
- Destructive actions that can be undone for a moment after they succeed.
- Inline actions in cards and list rows.
When not to use it
- Consequences need explanation or several choices; use Dialog.
- An everyday action needs no confirmation; use Button.
Installation
Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.
npx @swipeui/cli add confirm-morph- Adds
components/swipeui/ui/confirm-morph.tsx,components/swipeui/ui/use-confirm-morph.tsand 11 shared helpers. - Installs react-native-reanimated, react-native-svg, uniwind, react-native-worklets, clsx, tailwind-merge, expo-haptics, class-variance-authority. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { ConfirmMorph } from '@/components/swipeui/ui/confirm-morph';
<ConfirmMorph
label="Delete draft"
onConfirm={deleteDraft}
onUndo={restoreDraft}
confirmStyle="split"
labels={{ pending: 'Deleting', success: 'Deleted' }}
/>;Examples
The same split, tap-again and hold specimens run in the app and live preview. “Fail next action” and “Countdown outline” sit outside the control. Feedback stays on the action. Every specimen can demonstrate failure and retry through its external switch, including a failed Undo.
Split starts with a centered action. On activation, Cancel and Confirm spring apart from the middle toward the start and end edges. The single pending/result action returns to the center. RTL mirrors the split. Tap-again changes the armed action to a destructive tone. Hold first arms; then a continuous hold fills the surface, with ticks getting closer together. Releasing early, expiry, backgrounding or disabling cancels the hold without committing.
The independently colored outline drains around the rounded border during the confirmation window and on the separate Undo pill. Turning it off keeps the safety clocks. Undo may be asynchronous; a failed undo offers its own retry with a fresh undo window. Confirmation failure retries the already accepted action.
Settings
All windows are content timing in milliseconds, independent of motion feel. They must be finite and positive; minPending may be zero. The confirmation window includes the hold threshold.
| Setting | Default | Behavior |
|---|---|---|
confirmStyle | split | Independent split, tap-again or hold confirmation. |
state / defaultState / onStateChange | uncontrolled idle | Control the lifecycle or choose its starting step. Controlled owners apply every requested change. |
confirmWindow | 4000 | Cancel the armed step when this window expires. |
undoWindow | 5000 | Duration of the separate Undo or failed-undo retry pill. |
holdDuration | 1200 | Continuous armed hold required; an early lift never commits. |
minPending | 450 | Minimum visible pending time for both confirmation and undo. |
resetAfter | 1800 | Visibility of success without undo, restored feedback and confirmation failure. |
outlineTimer | true | Rounded remaining-time outline during arming and undo. |
outlineTimerColor | primary theme token | Independent countdown stroke color for confirmation and Undo; pass a resolved color value. |
holdFill | true | Meaningful hold fill, independently of the threshold and ticks. |
splitMotion | true | Both controls spring apart from the centered resting position. |
labelMorph | true | Current icon/label groups center at their visible width; control footprints stay stable. |
retryOnPress | true | Retry the accepted operation while failure is visible. |
haptics | true | All feedback, or independent { arm, hold, result } switches. |
haptics.arm | true | Warning notification when armed. |
haptics.hold | true | Accelerating selection ticks during a continuous hold. |
haptics.result | true | Success/error notifications for confirmation and undo. |
label | required | Resting action name. |
labels | built-in text | Independent confirm, tapAgain, hold, cancel, pending, success, error, undo, undoPending, undoError, undone labels. |
confirmLabel / successLabel / errorLabel | Confirm / Done / Try again | Legacy aliases; corresponding labels entries take priority. |
onConfirm / onUndo / onError | required / absent / absent | Application work, optional reversal and latest error callback. Return promises for async feedback. |
variant / tone | solid / destructive | Shared Button surfaces and tones. Tap-again confirmation and failures use destructive feedback; success uses success tone. |
size / shape | md / preset | Shared 36/44/52pt sizes and preset/pill corners; small targets expand to 44pt. Undo always has pill corners. |
block | false | Pass the shared full-width sizing treatment to the main surface within its reserved slot. |
highlight / glow | true / false | Shared solid-surface rim and optional glow. |
pressEffect | both | Shared scale/wash/both/none press feedback. |
disabled / disabledStyle | false / muted | Disable activation and cancel an unfinished hold; muted/dim treatment. Pending also reports busy and disabled. |
leadingIcon | absent | Button node or { color, size } render function, centered with the current label. |
motion | app feel | Shared press/morph/spinner roles. Reduce Motion removes travel and retains meaningful linear clock/fill progress. |
accessibilityLabel / accessibilityHint | action label / step hint | Resting spoken name and optional instruction. Dynamic steps speak their own labels. |
hitSlop | size default | Override the touch expansion. |
className / style / textClassName / testID | absent | Root and label overrides; parts append a suffix to the test identifier. |
API reference
ConfirmMorphProps
| Prop | Type | Default | Description |
|---|---|---|---|
motion? | | | The app's press character, or a local override. The app's motion feel, or a local override for the press, label and width springs. |
variant? | | | How much the button stands out: |
tone? | | | The colour family: |
size? | | | The height: |
shape? | | |
|
block? | | | Stretches the button to the full width of its container. |
leadingIcon? | | — | Content before the label: a node, or a function that receives |
highlight? | | | A faint rim of light along the top edge of solid buttons. |
glow? | | | A soft shadow in the tone's colour under solid buttons. |
pressEffect? | | | Feedback while pressed: |
disabledStyle? | | | How a disabled button looks: |
className? | | — | Classes merged over the style. |
textClassName? | | — | Classes for the label text. |
style? | | — | Style escape hatch for the container. |
label | | — | Resting action label. |
onConfirm | | — | Work called only after confirmation or the direct accessibility action. |
onUndo? | | | Optional asynchronous reversal. |
onError? | | | Latest confirmation or undo failure. |
confirmStyle? | | | Confirmation interaction; hold first arms, then requires a continuous hold. |
state? | | | Controlled lifecycle; apply onStateChange to accept changes. External changes invalidate pending UI settlement, not underlying work. |
defaultState? | | | Initial uncontrolled lifecycle. |
onStateChange? | | | Lifecycle changes requested by user actions, work and clocks. |
confirmWindow? | | | Armed lifetime in milliseconds; expiry cancels an unfinished hold. |
undoWindow? | | | Undo lifetime in milliseconds. A failed undo opens a fresh retry window. |
holdDuration? | | | Continuous hold threshold in milliseconds, independent of motion. |
minPending? | | | Minimum pending visibility for confirmation and undo, in milliseconds. |
resetAfter? | | | Success without undo, restored and confirmation-error visibility in milliseconds. |
outlineTimer? | | | Remaining-time outline for arming and undo; clocks still expire when hidden. |
outlineTimerColor? | | | Countdown stroke color for confirmation and Undo. Accepts a resolved color; otherwise uses the primary theme token. |
holdFill? | | | Show the meaningful hold fill; threshold and ticks remain independent. |
splitMotion? | | | Separate Cancel and Confirm from the centered resting action; Reduce Motion removes travel. |
labelMorph? | | | Animate changing labels; reserved widths remain. |
retryOnPress? | | | Retry accepted confirmation or undo while failure is visible. |
labels? | | | Independent text for every step. |
confirmLabel? | | | Legacy split label, overridden by labels.confirm. |
successLabel? | | | Legacy success label, overridden by labels.success. |
errorLabel? | | | Legacy error label, overridden by labels.error. |
haptics? | | | Global or independent arm, hold and result feedback. |
Composition and behavior
The idle button exposes Confirm <action> as a direct accessibility action, so a screen reader can bypass arming and holding. Cancel, timeout, accessibility escape and Android back dismiss the armed step. Lifecycle labels announce once; the timer never announces each frame. Undo has a separate accessible name and busy state.
Controlled values are idle, armed, pending, success, error, undo-pending, undo-error and undone. External state changes invalidate old UI settlement. They do not abort an application mutation already sent to a server. The application owns persistence and cancellation of underlying work.
Native runtime, VoiceOver/TalkBack, large Dynamic Type, device RTL, haptics, motion and recordings remain pending founder device review in milestone 7.9. Browser and unit evidence do not close those gates.
Behavior and gestures
- Split starts centered, then Cancel and Confirm separate toward the reading start/end edges; the single action recenters after confirmation or cancellation. RTL mirrors the split.
- Tap-again arms a destructive second tap. Hold first arms, then requires one continuous hold; early release never commits.
- The rounded outline drains for confirmWindow and again for undoWindow on a separate Undo pill. Hiding it does not remove the clocks.
- Async confirmation and undo show the shared ButtonSpinner for at least minPending. Accepted work cannot be duplicated.
- Failure retries the accepted operation; failed undo opens a new undoWindow for recovery. Expiry returns to idle.
- Cancel, timeout, escape/back and background cancel arming. Disabled interrupts an unfinished hold.
Accessibility
- The idle button exposes a direct Confirm <action> accessibility action, bypassing arming and hold.
- Every control has a spoken name; pending is busy and disabled. Cancel and Undo are separate targets.
- Lifecycle label changes are announced once, without countdown announcements. Small controls expand to 44pt touch targets.
- Native VoiceOver, TalkBack, back gestures, large text, RTL and haptic evidence remain pending.
Motion
- Uses the
press,morphandambientmotion roles, so it follows your app's feel. Passmotionto tune this one instance. - Shared Button press/label/spinner feedback. Morph-role layout springs separate both controls from the center; Reduce Motion and splitMotion=false remove split travel.
- Reduce Motion removes split and label travel. Meaningful linear outline and hold progress retain real content timing independently of motion feel.
Performance
- UI-thread progress and leaf animated styles; no per-frame React state or immediate JavaScript shared-value readback.
- Worklet closures capture only primitives/shared values, never browser CSS easing objects.
- use-async-action ignores stale results and unmount settlement. Hold and safety clocks clean up on state/lifecycle changes.
Notes for AI
- Return promises from onConfirm and onUndo; the caller owns persistence and cancellation of underlying work.
- Controlled owners must apply onStateChange. External lifecycle changes invalidate UI results; they do not abort a server mutation.
- Use independent outlineTimer, outlineTimerColor, holdFill, splitMotion, labelMorph, retryOnPress and haptics switches. The timer defaults to the primary token. Keep demo controls outside; failure/retry is available on all three specimen styles.
- Windows and holdDuration are positive milliseconds. confirmWindow includes the hold and may expire before completion.
- Native runtime, accessibility, motion and recordings cannot be inferred from source, browser or unit tests.
Compatibility
| Runs on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.