Hold to confirm
A continuous intentional hold with a tone fill, detents and safe async confirmation.
npx @swipeui/cli add hold-to-confirmWhen to use it
- Require deliberate confirmation when the consequence is already understood.
- Keep a compact destructive action and its pending/result feedback together.
When not to use it
- Replace an explanation that needs a dialog.
- Shorten a safety threshold when Reduce Motion is enabled.
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 hold-to-confirm- Adds
components/swipeui/ui/hold-to-confirm.tsx,components/swipeui/ui/use-hold-to-confirm.tsand 13 shared helpers. - Installs react-native-reanimated, uniwind, react-native-worklets, clsx, tailwind-merge, expo-haptics, class-variance-authority, react-native-svg. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { HoldToConfirm } from '@/components/swipeui/ui/hold-to-confirm';
<HoldToConfirm label="Hold to archive" confirmedLabel="Archived" onConfirm={archiveDraft} />;Examples
Confirm and Disabled. Use Fail next action on Confirm to see the retry state. The app and public preview use the same content and variant names. Demo settings sit outside the component and outcome feedback stays on the action.
Settings
| Setting | Default | Behavior |
|---|---|---|
label | absent | Visible resting action label. |
confirmedLabel | 'Confirmed' | Successful action label. |
pendingLabel | 'Confirming' | Pending action label. |
failureLabel | 'Hold to retry' | Failed action label; a fresh hold retries. |
holdFill | true | Show the tone fill independently of the safety clock. |
completionIcon | true | Draw the completion check independently of text feedback. |
onConfirm | absent | Called once per complete intentional hold; may return a promise. |
holdDuration | 1000 | Safety threshold in milliseconds, independent of motion. |
confirmed | undefined | Controlled completion; change back to false to allow another confirmation. |
defaultConfirmed | false | Initial uncontrolled completion. |
onConfirmedChange | undefined | Receives successful completion. |
holdTicks | true | Show haptic detents while held. |
tickInterval | 200 | Milliseconds between detents. |
minPending | 450 | Minimum pending visibility in milliseconds. |
onError | undefined | Reports failed confirmation work. |
disabled | false | Prevent confirmation and cancel an active hold. |
haptics | true | Global feedback or independent press/hold/result switches. |
motion | app feel | Motion feel; never shortens the safety threshold. |
variant | '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 | 'primary' for solid, tinted and plain; 'neutral' for outline and ghost | The colour family: primary, neutral, destructive or success. |
size | 'md' | The height: sm 36pt (with a 44pt touch target), md 44pt, lg 52pt. |
shape | 'preset' | preset follows your preset's control radius; pill is a capsule. |
block | false | Stretches the button to the full width of its container. |
loadingLabel | absent | Label shown while loading; defaults to the children. |
labelMorph | 'fade' | How a changed text label arrives: fade (the new label rises in as the old one fades), characters (only the changed letters roll in) or none. The width springs to fit either way. |
highlight | true | A faint rim of light along the top edge of solid buttons. |
glow | false | A soft shadow in the tone's colour under solid buttons. |
pressEffect | 'both' | Feedback while pressed: both scales and washes the surface, scale, wash or none. Text-only buttons dim their label instead of washing. |
disabledStyle | 'muted' | How a disabled button looks: muted mutes its fill and label; dim halves its opacity. |
palette | BUTTON_PALETTE | Colours that belong to the button's material rather than the theme (the top highlight). |
className | absent | Classes merged over the style. |
textClassName | absent | Classes for the label text. |
style | absent | Style escape hatch for the container. |
accessibilityLabel | current label | Optional spoken-name override. |
testID | undefined | Root identifier; parts append suffixes. |
haptics.press | true | Impact at the start of a deliberate hold. |
haptics.hold | true | Selection detents during the hold. |
haptics.result | true | Success or error outcome notification. |
Composition and behavior
holdDuration and tickInterval are positive milliseconds; minPending may be zero. Return confirmation work from onConfirm. Screen-reader activation and the explicit Confirm action bypass the physical hold. Confirmation state may be controlled through confirmed/onConfirmedChange.
A full continuous hold invokes onConfirm once. Early release, blur, background, disabling, configuration changes and unmount cancel an incomplete hold.
holdFill, holdTicks, tickInterval and completionIcon are independent. Meaningful progress keeps its full content-time threshold under Reduce Motion.
Promise work displays pending, then completed or a fresh hold-to-retry path. Controlled confirmed can be reset externally; there is no automatic repeat after success.
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
layout? | | — | Optional layout transition for composed controls; derive its values from useMotion. |
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. Motion feel; never shortens the safety threshold. |
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 |
trailingIcon? | | — | Content after the label: a node, or a function that receives |
trailingIconNudge? | | | Slides the trailing icon a little forward while pressed, mirrored in right-to-left layouts. |
loadingLabel? | | — | Label shown while loading; defaults to the children. |
loadingPlacement? | | | Where the spinner goes: |
singleLine? | | | Keep string labels and loading words on one clipped line. |
labelMorph? | | | How a changed text label arrives: |
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: |
glassStatus? | | — | Keeps a completed or failed action’s Glass status visible when the control is locked. |
palette? | | | Colours that belong to the button's material rather than the theme (the top highlight). |
className? | | — | Classes merged over the style. |
textClassName? | | — | Classes for the label text. |
style? | | — | Style escape hatch for the container. |
onConfirm | | — | Called once per complete intentional hold; may return a promise. |
holdDuration? | | | Safety threshold in milliseconds, independent of motion. |
confirmed? | | | Controlled completion; change back to false to allow another confirmation. |
defaultConfirmed? | | | Initial uncontrolled completion. |
onConfirmedChange? | | | Receives successful completion. |
holdTicks? | | | Show haptic detents while held. |
tickInterval? | | | Milliseconds between detents. |
minPending? | | | Minimum pending visibility in milliseconds. |
onError? | | | Reports failed confirmation work. |
haptics? | | | Global feedback or independent press/hold/result switches. |
label | | — | Visible resting action label. |
confirmedLabel? | | | Successful action label. |
pendingLabel? | | | Pending action label. |
failureLabel? | | | Failed action label; a fresh hold retries. |
holdFill? | | | Show the tone fill independently of the safety clock. |
completionIcon? | | | Draw the completion check independently of text feedback. |
Review gates
Founder app and existing pnpm-dev visual acceptance remains open. Native runtime, VoiceOver/TalkBack, haptics, motion, Dynamic Type, RTL and recordings remain pending founder-scheduled 7.9. Source, bundle and unit checks do not establish visual or native acceptance.
Behavior and gestures
- A full continuous hold invokes onConfirm once. Early release, blur, background, disabling, configuration changes and unmount cancel an incomplete hold.
- holdFill, holdTicks, tickInterval and completionIcon are independent. Meaningful progress keeps its full content-time threshold under Reduce Motion.
- Promise work displays pending, then completed or a fresh hold-to-retry path. Controlled confirmed can be reset externally; there is no automatic repeat after success.
Accessibility
- Named controls expose unavailable, busy and selected/progress state where applicable. Decorative layers are excluded from interaction.
- Meaningful outcome/availability announcements are distinct from clocks and decorative effects. Native VoiceOver/TalkBack, Dynamic Type, RTL and touch evidence remain pending for 7.9.
Motion
- Uses the
press,morph,numberandambientmotion roles, so it follows your app's feel. Passmotionto tune this one instance. - Every decorative duration/spring comes from the shared role helpers. Content clocks remain independent of motion feel.
- Reduce Motion retains readable outcome/progress feedback. Native motion/performance review remains pending.
Performance
- No new package, network service, telemetry or proprietary source.
- Async results and content timers clean up or invalidate after unmount; UI animation values stay on the UI thread.
Notes for AI
- holdDuration and tickInterval are positive milliseconds; minPending may be zero. Return confirmation work from onConfirm. Screen-reader activation and the explicit Confirm action bypass the physical hold. Confirmation state may be controlled through confirmed/onConfirmedChange.
- Founder app/web acceptance and all native runtime, accessibility, haptics, motion and recordings remain pending for 7.9.
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.