From ed28ef6b5b95e4bac40bc4543fe779ab17b48251 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 1 Dec 2020 06:40:01 +0400 Subject: [PATCH] Voice Chat UI improvements --- .../Display/Source/HapticFeedback.swift | 25 ++++++++++++++++--- .../GroupCallNavigationAccessoryPanel.swift | 6 +++++ .../Sources/VoiceChatController.swift | 4 +++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/submodules/Display/Source/HapticFeedback.swift b/submodules/Display/Source/HapticFeedback.swift index e0c135f16a..ef1159a88a 100644 --- a/submodules/Display/Source/HapticFeedback.swift +++ b/submodules/Display/Source/HapticFeedback.swift @@ -6,14 +6,27 @@ public enum ImpactHapticFeedbackStyle: Hashable { case light case medium case heavy + case soft + case rigid + case veryLight } @available(iOSApplicationExtension 10.0, iOS 10.0, *) private final class HapticFeedbackImpl { private lazy var impactGenerator: [ImpactHapticFeedbackStyle : UIImpactFeedbackGenerator] = { - [.light: UIImpactFeedbackGenerator(style: .light), - .medium: UIImpactFeedbackGenerator(style: .medium), - .heavy: UIImpactFeedbackGenerator(style: .heavy)] }() + if #available(iOSApplicationExtension 13.0, iOS 13.0, *) { + return [.light: UIImpactFeedbackGenerator(style: .light), + .medium: UIImpactFeedbackGenerator(style: .medium), + .heavy: UIImpactFeedbackGenerator(style: .heavy), + .soft: UIImpactFeedbackGenerator(style: .soft), + .rigid: UIImpactFeedbackGenerator(style: .rigid), + .veryLight: UIImpactFeedbackGenerator()] + } else { + return [.light: UIImpactFeedbackGenerator(style: .light), + .medium: UIImpactFeedbackGenerator(style: .medium), + .heavy: UIImpactFeedbackGenerator(style: .heavy)] + } + }() private lazy var selectionGenerator: UISelectionFeedbackGenerator? = { let generator = UISelectionFeedbackGenerator() @@ -64,7 +77,11 @@ private final class HapticFeedbackImpl { func impact(_ style: ImpactHapticFeedbackStyle) { if let impactGenerator = self.impactGenerator[style] { - impactGenerator.impactOccurred() + if #available(iOSApplicationExtension 13.0, iOS 13.0, *), case .veryLight = style { + impactGenerator.impactOccurred(intensity: 0.3) + } else { + impactGenerator.impactOccurred() + } } } diff --git a/submodules/TelegramCallsUI/Sources/GroupCallNavigationAccessoryPanel.swift b/submodules/TelegramCallsUI/Sources/GroupCallNavigationAccessoryPanel.swift index 0eadfb7230..17cb61c52f 100644 --- a/submodules/TelegramCallsUI/Sources/GroupCallNavigationAccessoryPanel.swift +++ b/submodules/TelegramCallsUI/Sources/GroupCallNavigationAccessoryPanel.swift @@ -86,6 +86,8 @@ public final class GroupCallNavigationAccessoryPanel: ASDisplayNode { private var callState: PresentationGroupCallState? + private let hapticFeedback = HapticFeedback() + private var currentData: GroupCallPanelData? private var validLayout: (CGSize, CGFloat, CGFloat)? @@ -195,11 +197,15 @@ public final class GroupCallNavigationAccessoryPanel: ASDisplayNode { } switch gestureRecognizer.state { case .began: + self.hapticFeedback.impact(.veryLight) + self.actionButtonPressGestureStartTime = CACurrentMediaTime() if callState.muteState != nil { call.setIsMuted(action: .muted(isPushToTalkActive: true)) } case .ended, .cancelled: + self.hapticFeedback.impact(.veryLight) + let timestamp = CACurrentMediaTime() if callState.muteState != nil || timestamp - self.actionButtonPressGestureStartTime < 0.1 { call.toggleIsMuted() diff --git a/submodules/TelegramCallsUI/Sources/VoiceChatController.swift b/submodules/TelegramCallsUI/Sources/VoiceChatController.swift index e2f2bbdb3f..a22d6d30ee 100644 --- a/submodules/TelegramCallsUI/Sources/VoiceChatController.swift +++ b/submodules/TelegramCallsUI/Sources/VoiceChatController.swift @@ -791,6 +791,8 @@ public final class VoiceChatController: ViewController { } switch gestureRecognizer.state { case .began: + self.hapticFeedback.impact(.veryLight) + self.actionButtonPressGestureStartTime = CACurrentMediaTime() self.actionButton.pressing = true if callState.muteState != nil { @@ -801,6 +803,8 @@ public final class VoiceChatController: ViewController { self.containerLayoutUpdated(layout, navigationHeight: navigationHeight, transition: .animated(duration: 0.3, curve: .spring)) } case .ended, .cancelled: + self.hapticFeedback.impact(.veryLight) + self.pushingToTalk = false self.actionButton.pressing = false let timestamp = CACurrentMediaTime()