Signal-iOS/SignalServiceKit/Util/HapticFeedback.swift
2026-03-24 16:09:03 -05:00

58 lines
1.6 KiB
Swift

//
// Copyright 2018 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//
public import UIKit
public class SelectionHapticFeedback {
private let feedbackGenerator = UISelectionFeedbackGenerator()
public init() {
AssertIsOnMainThread()
feedbackGenerator.prepare()
}
public func selectionChanged() {
DispatchQueue.main.async {
self.feedbackGenerator.selectionChanged()
self.feedbackGenerator.prepare()
}
}
}
public class NotificationHapticFeedback {
private let feedbackGenerator = UINotificationFeedbackGenerator()
public init() {
AssertIsOnMainThread()
feedbackGenerator.prepare()
}
public func notificationOccurred(_ notificationType: UINotificationFeedbackGenerator.FeedbackType) {
DispatchQueue.main.async {
self.feedbackGenerator.notificationOccurred(notificationType)
self.feedbackGenerator.prepare()
}
}
}
public class ImpactHapticFeedback {
public class func impactOccurred(style: UIImpactFeedbackGenerator.FeedbackStyle) {
DispatchQueue.main.async {
let generator = UIImpactFeedbackGenerator(style: style)
generator.prepare()
generator.impactOccurred()
}
}
public class func impactOccurred(style: UIImpactFeedbackGenerator.FeedbackStyle, intensity: CGFloat) {
DispatchQueue.main.async {
let generator = UIImpactFeedbackGenerator(style: style)
generator.prepare()
generator.impactOccurred(intensity: intensity)
}
}
}