-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHapticFeedback.swift
102 lines (85 loc) · 2.48 KB
/
HapticFeedback.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#if os(iOS)
import HapticEngineClient
import UIKit
extension HapticFeedback {
public static func custom<Generator: UIFeedbackGenerator>(
_ generator: Generator,
_ action: @escaping (Generator) -> Void
) -> HapticFeedback {
HapticFeedback(
prepare: { generator.prepare() },
action: { action(generator) }
)
}
public static var light: HapticFeedback {
.custom(UIImpactFeedbackGenerator(style: .light)) {
$0.impactOccurred()
}
}
public static var medium: HapticFeedback {
.custom(UIImpactFeedbackGenerator(style: .medium)) {
$0.impactOccurred()
}
}
public static var heavy: HapticFeedback {
.custom(UIImpactFeedbackGenerator(style: .heavy)) {
$0.impactOccurred()
}
}
public static var soft: HapticFeedback {
.custom(UIImpactFeedbackGenerator(style: .soft)) {
$0.impactOccurred()
}
}
public static var rigid: HapticFeedback {
.custom(UIImpactFeedbackGenerator(style: .rigid)) {
$0.impactOccurred()
}
}
public static func light(intensity: CGFloat) -> HapticFeedback {
.custom(UIImpactFeedbackGenerator(style: .light)) {
$0.impactOccurred(intensity: intensity)
}
}
public static func medium(intensity: CGFloat) -> HapticFeedback {
.custom(UIImpactFeedbackGenerator(style: .medium)) {
$0.impactOccurred(intensity: intensity)
}
}
public static func heavy(intensity: CGFloat) -> HapticFeedback {
.custom(UIImpactFeedbackGenerator(style: .heavy)) {
$0.impactOccurred(intensity: intensity)
}
}
public static func soft(intensity: CGFloat) -> HapticFeedback {
.custom(UIImpactFeedbackGenerator(style: .soft)) {
$0.impactOccurred(intensity: intensity)
}
}
public static func rigid(intensity: CGFloat) -> HapticFeedback {
.custom(UIImpactFeedbackGenerator(style: .rigid)) {
$0.impactOccurred(intensity: intensity)
}
}
public static var success: HapticFeedback {
.custom(UINotificationFeedbackGenerator()) {
$0.notificationOccurred(.success)
}
}
public static var warning: HapticFeedback {
.custom(UINotificationFeedbackGenerator()) {
$0.notificationOccurred(.success)
}
}
public static var error: HapticFeedback {
.custom(UINotificationFeedbackGenerator()) {
$0.notificationOccurred(.success)
}
}
public static var selection: HapticFeedback {
.custom(UISelectionFeedbackGenerator()) {
$0.selectionChanged()
}
}
}
#endif