Skip to content

Instantly share code, notes, and snippets.

View jamesyorke's full-sized avatar

James Yorke jamesyorke

View GitHub Profile
@christianselig
christianselig / LongPressButton.swift
Last active July 10, 2024 23:44
How to accomplish a long-pressable button in SwiftUI with two different techniques. The first just uses SwiftUI but due to the simultaneous gesture requirement you also have to ensure both don't fire concurrently. The second uses UIKit and wraps UIButton and UILongPressGestureRecognizer which natively handles this behavior.
import SwiftUI
// PURE SwiftUI way with State tracking to prevent double events
struct ContentView: View {
@State private var ignoreTapEvent = false
var body: some View {
Button {
guard !ignoreTapEvent else {