1
+ public struct TapGesture : Sendable , Hashable {
2
+ package var kind : TapGestureKind
3
+
4
+ /// The idiomatic "primary" interaction for the device, such as a left-click with the mouse
5
+ /// or normal tap on a touch screen.
6
+ public static let primary = TapGesture ( kind: . primary)
7
+ /// The idiomatic "secondary" interaction for the device, such as a right-click with the
8
+ /// mouse or long press on a touch screen.
9
+ public static let secondary = TapGesture ( kind: . secondary)
10
+ /// A long press of the same interaction type as ``primary``. May be equivalent to
11
+ /// ``secondary`` on some backends, particularly on mobile devices.
12
+ public static let longPress = TapGesture ( kind: . longPress)
13
+
14
+ package enum TapGestureKind {
15
+ case primary, secondary, longPress
16
+ }
17
+ }
18
+
1
19
extension View {
2
20
/// Adds an action to perform when the user taps or clicks this view.
3
21
///
4
- /// Any tappable elements within the view will no longer be tappable.
5
- public func onTapGesture( perform action: @escaping ( ) -> Void ) -> some View {
6
- OnTapGestureModifier ( body: TupleView1 ( self ) , action: action)
22
+ /// Any tappable elements within the view will no longer be tappable with the same gesture
23
+ /// type.
24
+ public func onTapGesture( gesture: TapGesture = . primary, perform action: @escaping ( ) -> Void )
25
+ -> some View
26
+ {
27
+ OnTapGestureModifier ( body: TupleView1 ( self ) , gesture: gesture, action: action)
7
28
}
8
29
9
30
/// Adds an action to run when this view is clicked. Any clickable elements
10
31
/// within the view will no longer be clickable.
11
- @available ( * , deprecated, renamed: " onTapGesture(perform:) " )
32
+ @available ( * , deprecated, renamed: " onTapGesture(gesture: perform:) " )
12
33
public func onClick( perform action: @escaping ( ) -> Void ) -> some View {
13
34
onTapGesture ( perform: action)
14
35
}
@@ -18,6 +39,7 @@ struct OnTapGestureModifier<Content: View>: TypeSafeView {
18
39
typealias Children = TupleView1 < Content > . Children
19
40
20
41
var body : TupleView1 < Content >
42
+ var gesture : TapGesture
21
43
var action : ( ) -> Void
22
44
23
45
func children< Backend: AppBackend > (
@@ -36,7 +58,7 @@ struct OnTapGestureModifier<Content: View>: TypeSafeView {
36
58
_ children: Children ,
37
59
backend: Backend
38
60
) -> Backend . Widget {
39
- backend. createTapGestureTarget ( wrapping: children. child0. widget. into ( ) )
61
+ backend. createTapGestureTarget ( wrapping: children. child0. widget. into ( ) , gesture : gesture )
40
62
}
41
63
42
64
func update< Backend: AppBackend > (
@@ -55,7 +77,7 @@ struct OnTapGestureModifier<Content: View>: TypeSafeView {
55
77
)
56
78
if !dryRun {
57
79
backend. setSize ( of: widget, to: childResult. size. size)
58
- backend. updateTapGestureTarget ( widget, action: action)
80
+ backend. updateTapGestureTarget ( widget, gesture : gesture , action: action)
59
81
}
60
82
return childResult
61
83
}
0 commit comments