Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// WatchKitFeedbackImplementation.swift
// OpenSwiftUI
//
// Audited for 6.5.4
// Status: Complete

#if os(watchOS)
import WatchKit
import OpenSwiftUICore

// MARK: - View + platformSensoryFeedback

extension View {
nonisolated func platformSensoryFeedback<Base>(
_ base: Base
) -> some View where Base: SensoryFeedbackGeneratorModifier {
modifier(base)
}
}

// MARK: - WatchKitFeedbackImplementation

struct WatchKitFeedbackImplementation: PlatformSensoryFeedback {
var haptic: WKHapticType

func setUp() {
_openSwiftUIEmptyStub()
}

func tearDown() {
_openSwiftUIEmptyStub()
}

func generate() {
WKInterfaceDevice.current().play(haptic)
}
}

// MARK: - FeedbackRequestContext

struct FeedbackRequestContext {
func implementation(type: SensoryFeedback.FeedbackType) -> (any PlatformSensoryFeedback)? {
switch type {
case .success: WatchKitFeedbackImplementation(haptic: .success)
case .warning: WatchKitFeedbackImplementation(haptic: .retry)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For .warning, consider using WKHapticType.notification rather than .retry, since .retry reads more like “temporary failure/try again” than a warning/notification-style alert on watchOS.

🤖 Was this useful? React with 👍 or 👎

case .error: WatchKitFeedbackImplementation(haptic: .failure)
case .increase: WatchKitFeedbackImplementation(haptic: .directionUp)
case .decrease: WatchKitFeedbackImplementation(haptic: .directionDown)
case .start: WatchKitFeedbackImplementation(haptic: .start)
case .stop: WatchKitFeedbackImplementation(haptic: .stop)
case .selection, .impactWeight, .impactFlexibility: WatchKitFeedbackImplementation(haptic: .click)
default: nil
}
}
}
#endif
Loading