SwipeUI

Confirm morph

Centered split, second-tap and hold confirmation with colored countdown outlines, asynchronous feedback and timed Undo.

npx @swipeui/cli add confirm-morph
Variant
Preset
Material
Scheme
Feel
Real free component with a browser animation bridge. Native motion, haptics and materials need a device.

When 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.ts and 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 install so versions match your SDK.

Usage

app/drafts.tsx
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.

SettingDefaultBehavior
confirmStylesplitIndependent split, tap-again or hold confirmation.
state / defaultState / onStateChangeuncontrolled idleControl the lifecycle or choose its starting step. Controlled owners apply every requested change.
confirmWindow4000Cancel the armed step when this window expires.
undoWindow5000Duration of the separate Undo or failed-undo retry pill.
holdDuration1200Continuous armed hold required; an early lift never commits.
minPending450Minimum visible pending time for both confirmation and undo.
resetAfter1800Visibility of success without undo, restored feedback and confirmation failure.
outlineTimertrueRounded remaining-time outline during arming and undo.
outlineTimerColorprimary theme tokenIndependent countdown stroke color for confirmation and Undo; pass a resolved color value.
holdFilltrueMeaningful hold fill, independently of the threshold and ticks.
splitMotiontrueBoth controls spring apart from the centered resting position.
labelMorphtrueCurrent icon/label groups center at their visible width; control footprints stay stable.
retryOnPresstrueRetry the accepted operation while failure is visible.
hapticstrueAll feedback, or independent { arm, hold, result } switches.
haptics.armtrueWarning notification when armed.
haptics.holdtrueAccelerating selection ticks during a continuous hold.
haptics.resulttrueSuccess/error notifications for confirmation and undo.
labelrequiredResting action name.
labelsbuilt-in textIndependent confirm, tapAgain, hold, cancel, pending, success, error, undo, undoPending, undoError, undone labels.
confirmLabel / successLabel / errorLabelConfirm / Done / Try againLegacy aliases; corresponding labels entries take priority.
onConfirm / onUndo / onErrorrequired / absent / absentApplication work, optional reversal and latest error callback. Return promises for async feedback.
variant / tonesolid / destructiveShared Button surfaces and tones. Tap-again confirmation and failures use destructive feedback; success uses success tone.
size / shapemd / presetShared 36/44/52pt sizes and preset/pill corners; small targets expand to 44pt. Undo always has pill corners.
blockfalsePass the shared full-width sizing treatment to the main surface within its reserved slot.
highlight / glowtrue / falseShared solid-surface rim and optional glow.
pressEffectbothShared scale/wash/both/none press feedback.
disabled / disabledStylefalse / mutedDisable activation and cancel an unfinished hold; muted/dim treatment. Pending also reports busy and disabled.
leadingIconabsentButton node or { color, size } render function, centered with the current label.
motionapp feelShared press/morph/spinner roles. Reduce Motion removes travel and retains meaningful linear clock/fill progress.
accessibilityLabel / accessibilityHintaction label / step hintResting spoken name and optional instruction. Dynamic steps speak their own labels.
hitSlopsize defaultOverride the touch expansion.
className / style / textClassName / testIDabsentRoot and label overrides; parts append a suffix to the test identifier.

API reference

ConfirmMorphProps

PropTypeDefaultDescription
motion?MotionOverridethe app's feel (`smooth` without a provider)

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?ButtonVariant'solid'

How much the button stands out: solid, tinted (a soft wash of the tone), outline, ghost (no fill until pressed) or plain (text only). The 1.x names default, secondary and destructive still work as solid primary, neutral and destructive.

tone?ButtonTone'primary' for solid, tinted and plain; 'neutral' for outline and ghost

The colour family: primary, neutral, destructive or success.

size?ButtonSize'md'

The height: sm 36pt (with a 44pt touch target), md 44pt, lg 52pt.

shape?ButtonShape'preset'

preset follows your preset's control radius; pill is a capsule.

block?booleanfalse

Stretches the button to the full width of its container.

leadingIcon?ButtonIcon—

Content before the label: a node, or a function that receives { color, size }.

highlight?booleantrue

A faint rim of light along the top edge of solid buttons.

glow?booleanfalse

A soft shadow in the tone's colour under solid buttons.

pressEffect?ButtonPressEffect'both'

Feedback while pressed: both scales and washes the surface, scale, wash or none. Text-only buttons dim their label instead of washing.

disabledStyle?ButtonDisabledStyle'muted'

How a disabled button looks: muted mutes its fill and label; dim halves its opacity.

className?string—

Classes merged over the style.

textClassName?string—

Classes for the label text.

style?StyleProp<ViewStyle>—

Style escape hatch for the container.

labelstring—

Resting action label.

onConfirm() => void | Promise<void>—

Work called only after confirmation or the direct accessibility action.

onUndo?(() => void | Promise<void>)undefined

Optional asynchronous reversal.

onError?((error: unknown) => void)undefined

Latest confirmation or undo failure.

confirmStyle?"hold" | "split" | "tap-again"'split'

Confirmation interaction; hold first arms, then requires a continuous hold.

state?ConfirmMorphStateundefined

Controlled lifecycle; apply onStateChange to accept changes. External changes invalidate pending UI settlement, not underlying work.

defaultState?ConfirmMorphState'idle'

Initial uncontrolled lifecycle.

onStateChange?((state: ConfirmMorphState) => void)undefined

Lifecycle changes requested by user actions, work and clocks.

confirmWindow?number4000

Armed lifetime in milliseconds; expiry cancels an unfinished hold.

undoWindow?number5000

Undo lifetime in milliseconds. A failed undo opens a fresh retry window.

holdDuration?number1200

Continuous hold threshold in milliseconds, independent of motion.

minPending?number450

Minimum pending visibility for confirmation and undo, in milliseconds.

resetAfter?number1800

Success without undo, restored and confirmation-error visibility in milliseconds.

outlineTimer?booleantrue

Remaining-time outline for arming and undo; clocks still expire when hidden.

outlineTimerColor?stringprimary token

Countdown stroke color for confirmation and Undo. Accepts a resolved color; otherwise uses the primary theme token.

holdFill?booleantrue

Show the meaningful hold fill; threshold and ticks remain independent.

splitMotion?booleantrue

Separate Cancel and Confirm from the centered resting action; Reduce Motion removes travel.

labelMorph?booleantrue

Animate changing labels; reserved widths remain.

retryOnPress?booleantrue

Retry accepted confirmation or undo while failure is visible.

labels?ConfirmMorphLabelsbuilt-in labels

Independent text for every step.

confirmLabel?string'Confirm'

Legacy split label, overridden by labels.confirm.

successLabel?string'Done'

Legacy success label, overridden by labels.success.

errorLabel?string'Try again'

Legacy error label, overridden by labels.error.

haptics?boolean | ConfirmMorphHapticstrue

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, morph and ambient motion roles, so it follows your app's feel. Pass motion to 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 onSupported
Expo SDK 57Yes
Expo SDK 58Yes
React Native CLI (with Expo modules)Yes
Expo GoYes
iOSYes
AndroidYes

This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.

Related items