mirror of
https://github.com/mastodon/mastodon-ios.git
synced 2024-12-11 16:16:48 +01:00
4ea600403b
* Move all UI*FeedbackGenerators to FeedbackGenerator and disable them for now (IOS-247) * Fix copyright header * Remove empty private constructor
41 lines
1.3 KiB
Swift
41 lines
1.3 KiB
Swift
// Copyright © 2024 Mastodon gGmbH. All rights reserved.
|
|
|
|
import UIKit
|
|
|
|
public class FeedbackGenerator {
|
|
|
|
private let lightImpactFeedbackGenerator = UIImpactFeedbackGenerator(style: .light)
|
|
private let mediumImpactFeedbackGenerator = UIImpactFeedbackGenerator(style: .medium)
|
|
private let notificationFeedbackGenerator = UINotificationFeedbackGenerator()
|
|
private let selectionFeedbackGenerator = UISelectionFeedbackGenerator()
|
|
|
|
public enum Impact {
|
|
case light, medium
|
|
}
|
|
|
|
public enum Feedback {
|
|
case impact(Impact)
|
|
case notification(UINotificationFeedbackGenerator.FeedbackType)
|
|
case selectionChanged
|
|
}
|
|
|
|
public static let shared = FeedbackGenerator()
|
|
public var isEnabled = true
|
|
|
|
public func generate(_ feedback: Feedback) {
|
|
guard isEnabled else { return }
|
|
DispatchQueue.main.async { [self] in
|
|
switch feedback {
|
|
case .impact(.light):
|
|
lightImpactFeedbackGenerator.impactOccurred()
|
|
case .impact(.medium):
|
|
mediumImpactFeedbackGenerator.impactOccurred()
|
|
case let .notification(type):
|
|
notificationFeedbackGenerator.notificationOccurred(type)
|
|
case .selectionChanged:
|
|
selectionFeedbackGenerator.selectionChanged()
|
|
}
|
|
}
|
|
}
|
|
}
|