Warning, /network/kdeconnect-ios/KDE Connect/KDE Connect/Views/Abstracted Views/TapRecognizerViewModifier.swift is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2021 Lucas Wang <lucas.wang@tuta.io> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 // Original header below: 0008 // 0009 // TapRecognizerViewModifier.swift 0010 // KDE Connect Test 0011 // 0012 // Created by Lucas Wang on 2021-09-06. 0013 // 0014 0015 import SwiftUI 0016 0017 struct TapRecognizerViewModifier: ViewModifier { 0018 @State private var singleTapIsTaped = false 0019 0020 let tapSensitivity: Double 0021 let singleTapAction: () -> Void 0022 let doubleTapAction: () -> Void 0023 0024 init( 0025 tapSensitivity: Double, 0026 singleTapAction: @escaping () -> Void, 0027 doubleTapAction: @escaping () -> Void 0028 ) { 0029 self.tapSensitivity = tapSensitivity 0030 self.singleTapAction = singleTapAction 0031 self.doubleTapAction = doubleTapAction 0032 } 0033 0034 func body(content: Content) -> some View { 0035 content 0036 .gesture(simultaneouslyGesture) 0037 } 0038 0039 private var singleTapGesture: some Gesture { 0040 TapGesture(count: 1) 0041 .onEnded { 0042 singleTapIsTaped = true 0043 0044 DispatchQueue.main.asyncAfter(deadline: .now() + tapSensitivity) { 0045 if singleTapIsTaped { 0046 singleTapAction() 0047 } 0048 } 0049 } 0050 } 0051 0052 private var doubleTapGesture: some Gesture { 0053 TapGesture(count: 2) 0054 .onEnded { 0055 singleTapIsTaped = false 0056 doubleTapAction() 0057 } 0058 } 0059 0060 private var simultaneouslyGesture: some Gesture { 0061 singleTapGesture.simultaneously(with: doubleTapGesture) 0062 } 0063 } 0064 0065 extension View { 0066 func tapRecognizer( 0067 tapSensitivity: Double, 0068 singleTapAction: @escaping () -> Void, 0069 doubleTapAction: @escaping () -> Void 0070 ) -> some View { 0071 modifier(TapRecognizerViewModifier(tapSensitivity: tapSensitivity, 0072 singleTapAction: singleTapAction, 0073 doubleTapAction: doubleTapAction)) 0074 } 0075 }