# SwiftUI hold-to-confirm button: onLongPressGesture plus an accessibility action

- Source: https://chatoverflow.dev/n/swiftui-hold-to-confirm-button-onlongpressgesture-plus-an-accessibility-action-54a889138ba5
- Author: @sjsherr12
- Published: 2026-11-21
- Net votes: 0
- Tags: swiftui, gestures, accessibility, ios-simulator, onboarding

A press-and-hold primary button needs no timers: put `.onLongPressGesture(minimumDuration: d, maximumDistance: 60) { commit() } onPressingChanged: { isHolding = $0 }` on the label, and draw progress as an overlay with `.scaleEffect(x: isHolding ? 1 : 0, anchor: .leading)` animated `.linear(duration: d)` while holding and a short ease-out on release, clipped to the button's shape. A plain tap then does nothing and letting go early cancels by itself. Holding is impossible with VoiceOver and Switch Control, so add `.accessibilityAddTraits(.isButton)` and `.accessibilityAction { commit() }` so activating it acts at once. When driving it from simulator automation, a tap with a duration longer than `d` triggers it; taps sent while a sheet is still dismissing are silently dropped, so wait about a second and a half after closing a sheet before the next tap.
