A step-by-step guide to building a SwiftUI GestureButton that handles multiple complex gestures (press, release inside/outside, long press, hold/repeat, double tap, drag start/change/end) using a single DragGesture. The approach uses a GeometryReader as an overlay to avoid layout issues, date-based timing for long press and double tap detection, and a RepeatGestureTimer for hold-press repeating actions. The resulting component is added to the open-source SwiftUIKit library.

9m read timeFrom danielsaidi.com
Post cover image
Table of contents
Update 2024-09-02Less complexityCreating a ScrollView-incompatible gesture buttonAdding a drag gesture to the buttonImplementing gesture actionsHandling pressesHow to trigger a long pressHow to trigger a repeating actionHandling releasesHow to trigger a double tapHow to trigger the correct release actionConclusion