Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions DeltaCore/UI/Controller/ButtonsInputView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ class ButtonsInputView: UIView

private let imageView = UIImageView(frame: .zero)

private let feedbackGenerator = UIImpactFeedbackGenerator(style: .medium)

private var downFeedbackGenerator: UIImpactFeedbackGenerator?
private var upFeedbackGenerator: UIImpactFeedbackGenerator?

private var touchInputsMappingDictionary: [UITouch: Set<AnyInput>] = [:]
private var previousTouchInputs = Set<AnyInput>()
private var touchInputs: Set<AnyInput> {
Expand All @@ -47,8 +48,17 @@ class ButtonsInputView: UIView

self.isMultipleTouchEnabled = true

self.feedbackGenerator.prepare()
if #available(iOS 13.0, *) {
self.downFeedbackGenerator = UIImpactFeedbackGenerator(style: .rigid)
self.upFeedbackGenerator = UIImpactFeedbackGenerator(style: .soft)
} else {
self.downFeedbackGenerator = UIImpactFeedbackGenerator(style: .medium)
self.upFeedbackGenerator = UIImpactFeedbackGenerator(style: .light)
}

self.downFeedbackGenerator?.prepare()
self.upFeedbackGenerator?.prepare()

self.imageView.translatesAutoresizingMaskIntoConstraints = false
self.addSubview(self.imageView)

Expand Down Expand Up @@ -140,7 +150,7 @@ private extension ButtonsInputView
{
switch UIDevice.current.feedbackSupportLevel
{
case .feedbackGenerator: self.feedbackGenerator.impactOccurred()
case .feedbackGenerator: self.downFeedbackGenerator?.impactOccurred()
case .basic, .unsupported: UIDevice.current.vibrate()
}
}
Expand All @@ -149,6 +159,15 @@ private extension ButtonsInputView
if !deactivatedInputs.isEmpty
{
self.deactivateInputsHandler?(deactivatedInputs)

if self.isHapticFeedbackEnabled
{
switch UIDevice.current.feedbackSupportLevel
{
case .feedbackGenerator: self.upFeedbackGenerator?.impactOccurred()
case .basic, .unsupported: break
}
}
}
}
}