Voice Chat UI improvements

This commit is contained in:
Ilya Laktyushin 2020-12-01 06:40:01 +04:00
parent c053f853d1
commit ed28ef6b5b
3 changed files with 31 additions and 4 deletions

View File

@ -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()
}
}
}

View File

@ -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()

View File

@ -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()