File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed
Sources/OpenSwiftUI/View/Control/SensoryFeedback/WatchKit Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ //
2+ // WatchKitFeedbackImplementation.swift
3+ // OpenSwiftUI
4+ //
5+ // Audited for 6.5.4
6+ // Status: Complete
7+
8+ #if os(watchOS)
9+ import WatchKit
10+ import OpenSwiftUICore
11+
12+ // MARK: - View + platformSensoryFeedback
13+
14+ extension View {
15+ nonisolated func platformSensoryFeedback< Base> (
16+ _ base: Base
17+ ) -> some View where Base: SensoryFeedbackGeneratorModifier {
18+ modifier ( base)
19+ }
20+ }
21+
22+ // MARK: - WatchKitFeedbackImplementation
23+
24+ struct WatchKitFeedbackImplementation : PlatformSensoryFeedback {
25+ var haptic : WKHapticType
26+
27+ func setUp( ) {
28+ _openSwiftUIEmptyStub ( )
29+ }
30+
31+ func tearDown( ) {
32+ _openSwiftUIEmptyStub ( )
33+ }
34+
35+ func generate( ) {
36+ WKInterfaceDevice . current ( ) . play ( haptic)
37+ }
38+ }
39+
40+ // MARK: - FeedbackRequestContext
41+
42+ struct FeedbackRequestContext {
43+ func implementation( type: SensoryFeedback . FeedbackType ) -> ( any PlatformSensoryFeedback ) ? {
44+ switch type {
45+ case . success: WatchKitFeedbackImplementation ( haptic: . success)
46+ case . warning: WatchKitFeedbackImplementation ( haptic: . retry)
47+ case . error: WatchKitFeedbackImplementation ( haptic: . failure)
48+ case . increase: WatchKitFeedbackImplementation ( haptic: . directionUp)
49+ case . decrease: WatchKitFeedbackImplementation ( haptic: . directionDown)
50+ case . start: WatchKitFeedbackImplementation ( haptic: . start)
51+ case . stop: WatchKitFeedbackImplementation ( haptic: . stop)
52+ case . selection, . impactWeight, . impactFlexibility: WatchKitFeedbackImplementation ( haptic: . click)
53+ default : nil
54+ }
55+ }
56+ }
57+ #endif
You can’t perform that action at this time.
0 commit comments