TM-SGNL-iOS/SignalServiceKit/Util/HapticFeedback.swift
TeleMessage developers dde0620daf initial commit
2025-05-03 12:28:28 -07:00

57 lines
1.6 KiB
Swift

//
// Copyright 2018 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//
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)
}
}
}