SPB Git

Repository Public

Haptics.swift 1.3 KB 32 lines swift

1//2//  SP Chat iOS3//  File: SPChat-iOS/Components/Haptics.swift4//  Description: Haptic feedback vocabulary of the app (respects the user's preference).5//6//  Author: Simon-Pierre Boucher7//  Contact: contact@spboucher.ai8//910import UIKit1112@MainActor13final class Haptics {14    private let preferences: Preferences15    private let light = UIImpactFeedbackGenerator(style: .light)16    private let soft = UIImpactFeedbackGenerator(style: .soft)17    private let notification = UINotificationFeedbackGenerator()18    private let selectionGenerator = UISelectionFeedbackGenerator()1920    init(preferences: Preferences) { self.preferences = preferences }2122    /// Message sent, action triggered.23    func tap() { if preferences.hapticsEnabled { light.impactOccurred() } }24    /// Copy, toggle.25    func soften() { if preferences.hapticsEnabled { soft.impactOccurred(intensity: 0.7) } }26    func selection() { if preferences.hapticsEnabled { selectionGenerator.selectionChanged() } }27    /// An answer finished.28    func success() { if preferences.hapticsEnabled { notification.notificationOccurred(.success) } }29    func warning() { if preferences.hapticsEnabled { notification.notificationOccurred(.warning) } }30    func error() { if preferences.hapticsEnabled { notification.notificationOccurred(.error) } }31}32
Files main
Menu

Theme