Files
swiftapp/swift/Sources/Core/Design/Haptics.swift

34 lines
869 B
Swift
Raw Normal View History

import SwiftUI
#if os(iOS)
import UIKit
#elseif os(macOS)
import AppKit
#endif
enum Haptics {
static func success() {
#if os(iOS)
UINotificationFeedbackGenerator().notificationOccurred(.success)
#elseif os(macOS)
NSHapticFeedbackManager.defaultPerformer.perform(.levelChange, performanceTime: .now)
#endif
}
static func warning() {
#if os(iOS)
UINotificationFeedbackGenerator().notificationOccurred(.warning)
#elseif os(macOS)
NSHapticFeedbackManager.defaultPerformer.perform(.alignment, performanceTime: .now)
#endif
}
static func selection() {
#if os(iOS)
UISelectionFeedbackGenerator().selectionChanged()
#elseif os(macOS)
NSHapticFeedbackManager.defaultPerformer.perform(.alignment, performanceTime: .now)
#endif
}
}