From d0f349901562ec1f8c2fbd656b8a15672547dcc1 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Mon, 30 Nov 2020 17:55:36 +0400 Subject: [PATCH] Voice Chat UI fixes --- .../Sources/Node/ChatListItem.swift | 6 ++- .../Sources/CallStatusBarNode.swift | 8 ++-- .../Sources/PresentationGroupCall.swift | 1 - .../Sources/VoiceChatActionButton.swift | 43 +++++++++++-------- .../Sources/VoiceChatController.swift | 2 +- 5 files changed, 35 insertions(+), 25 deletions(-) diff --git a/submodules/ChatListUI/Sources/Node/ChatListItem.swift b/submodules/ChatListUI/Sources/Node/ChatListItem.swift index ce9e20e2d9..899fa9186f 100644 --- a/submodules/ChatListUI/Sources/Node/ChatListItem.swift +++ b/submodules/ChatListUI/Sources/Node/ChatListItem.swift @@ -1872,7 +1872,11 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { transition.updateFrame(node: self.avatarNode, frame: avatarFrame) var onlineFrame = self.onlineNode.frame - onlineFrame.origin.x = avatarFrame.maxX - onlineFrame.width - 2.0 + if self.onlineIsVoiceChat { + onlineFrame.origin.x = avatarFrame.maxX - onlineFrame.width + 1.0 - UIScreenPixel + } else { + onlineFrame.origin.x = avatarFrame.maxX - onlineFrame.width - 2.0 + } transition.updateFrame(node: self.onlineNode, frame: onlineFrame) var titleOffset: CGFloat = 0.0 diff --git a/submodules/TelegramCallsUI/Sources/CallStatusBarNode.swift b/submodules/TelegramCallsUI/Sources/CallStatusBarNode.swift index 8a87ac809a..977f43587b 100644 --- a/submodules/TelegramCallsUI/Sources/CallStatusBarNode.swift +++ b/submodules/TelegramCallsUI/Sources/CallStatusBarNode.swift @@ -262,9 +262,9 @@ private class CallStatusBarBackgroundNode: ASDisplayNode { let bigCurveRange: CurveRange = (0.1, 1.0) let size = CGSize(width: 375.0, height: 44.0) - let smallCurve = Curve(size: size, alpha: 1.0, pointsCount: 10, minRandomness: 1, maxRandomness: 1, minSpeed: 1.5, maxSpeed: 7, minOffset: smallCurveRange.min, maxOffset: smallCurveRange.max) - let mediumCurve = Curve(size: size, alpha: 0.55, pointsCount: 10, minRandomness: 1, maxRandomness: 2, minSpeed: 1.5, maxSpeed: 7, minOffset: mediumCurveRange.min, maxOffset: mediumCurveRange.max) - let largeCurve = Curve(size: size, alpha: 0.35, pointsCount: 10, minRandomness: 1, maxRandomness: 2, minSpeed: 1.5, maxSpeed: 7, minOffset: bigCurveRange.min, maxOffset: bigCurveRange.max) + let smallCurve = Curve(size: size, alpha: 1.0, pointsCount: 6, minRandomness: 1, maxRandomness: 1, minSpeed: 2.5, maxSpeed: 7, minOffset: smallCurveRange.min, maxOffset: smallCurveRange.max) + let mediumCurve = Curve(size: size, alpha: 0.55, pointsCount: 6, minRandomness: 1, maxRandomness: 2, minSpeed: 2.5, maxSpeed: 7, minOffset: mediumCurveRange.min, maxOffset: mediumCurveRange.max) + let largeCurve = Curve(size: size, alpha: 0.35, pointsCount: 6, minRandomness: 1, maxRandomness: 2, minSpeed: 2.5, maxSpeed: 7, minOffset: bigCurveRange.min, maxOffset: bigCurveRange.max) self.curves = [smallCurve, mediumCurve, largeCurve] @@ -312,6 +312,7 @@ private class CallStatusBarBackgroundNode: ASDisplayNode { animator = ConstantDisplayLinkAnimator(update: { [weak self] in self?.updateAnimations() }) + animator.frameInterval = 2 self.animator = animator } animator.isPaused = false @@ -366,6 +367,7 @@ private class CallStatusBarBackgroundNode: ASDisplayNode { return } + context.interpolationQuality = .low context.setBlendMode(.normal) var locations: [CGFloat] = [0.0, 1.0] diff --git a/submodules/TelegramCallsUI/Sources/PresentationGroupCall.swift b/submodules/TelegramCallsUI/Sources/PresentationGroupCall.swift index fcd24d9848..247df93106 100644 --- a/submodules/TelegramCallsUI/Sources/PresentationGroupCall.swift +++ b/submodules/TelegramCallsUI/Sources/PresentationGroupCall.swift @@ -610,7 +610,6 @@ public final class PresentationGroupCallImpl: PresentationGroupCall { for participant in state.participants { members.participants.append(participant) - if topParticipants.count < 3 { topParticipants.append(participant) } diff --git a/submodules/TelegramCallsUI/Sources/VoiceChatActionButton.swift b/submodules/TelegramCallsUI/Sources/VoiceChatActionButton.swift index 2905e1deee..1028aca33c 100644 --- a/submodules/TelegramCallsUI/Sources/VoiceChatActionButton.swift +++ b/submodules/TelegramCallsUI/Sources/VoiceChatActionButton.swift @@ -46,7 +46,7 @@ private protocol VoiceChatActionButtonBackgroundNodeContext { var isAnimating: Bool { get } func updateAnimations() - func drawingState() -> VoiceChatActionButtonBackgroundNodeState + func drawingState(transition: VoiceChatActionButtonBackgroundNodeTransitionState?) -> VoiceChatActionButtonBackgroundNodeState } private protocol VoiceChatActionButtonBackgroundNodeState: NSObjectProtocol { @@ -76,7 +76,7 @@ private final class VoiceChatActionButtonBackgroundNodeConnectingContext: VoiceC func updateAnimations() { } - func drawingState() -> VoiceChatActionButtonBackgroundNodeState { + func drawingState(transition: VoiceChatActionButtonBackgroundNodeTransitionState?) -> VoiceChatActionButtonBackgroundNodeState { return VoiceChatActionButtonBackgroundNodeConnectingState(blueGradient: self.blueGradient) } } @@ -106,7 +106,7 @@ private final class VoiceChatActionButtonBackgroundNodeDisabledContext: VoiceCha func updateAnimations() { } - func drawingState() -> VoiceChatActionButtonBackgroundNodeState { + func drawingState(transition: VoiceChatActionButtonBackgroundNodeTransitionState?) -> VoiceChatActionButtonBackgroundNodeState { return VoiceChatActionButtonBackgroundNodeDisabledState() } } @@ -347,11 +347,24 @@ private final class VoiceChatActionButtonBackgroundNodeBlobContext: VoiceChatAct } } - func drawingState() -> VoiceChatActionButtonBackgroundNodeState { + func drawingState(transition: VoiceChatActionButtonBackgroundNodeTransitionState?) -> VoiceChatActionButtonBackgroundNodeState { var blobs: [BlobDrawingState] = [] for blob in self.blobs { if let path = blob.currentShape?.copy() as? UIBezierPath { - blobs.append(BlobDrawingState(size: blob.size, path: path, scale: blob.currentScale, alpha: blob.alpha)) + let size = CGSize(width: 300.0, height: 300.0) + var appearanceProgress: CGFloat = 1.0 + if let transition = transition, transition.previousState == .connecting || transition.previousState == .disabled { + appearanceProgress = transition.transition + } + let offset = (size.width - blob.size.width) / 2.0 + let toOrigin = CGAffineTransform(translationX: -size.width / 2.0 + offset, y: -size.height / 2.0 + offset) + let fromOrigin = CGAffineTransform(translationX: size.width / 2.0, y: size.height / 2.0) + + path.apply(toOrigin) + path.apply(CGAffineTransform(scaleX: blob.currentScale * appearanceProgress, y: blob.currentScale * appearanceProgress)) + path.apply(fromOrigin) + + blobs.append(BlobDrawingState(size: blob.size, path: path.cgPath, scale: blob.currentScale, alpha: blob.alpha)) } } return VoiceChatActionButtonBackgroundNodeBlobState(size: self.size, active: self.active, activeTransitionArguments: self.activeTransitionArguments, blueGradient: self.blueGradient, greenGradient: self.greenGradient, blobs: blobs) @@ -360,11 +373,11 @@ private final class VoiceChatActionButtonBackgroundNodeBlobContext: VoiceChatAct private class BlobDrawingState: NSObject { let size: CGSize - let path: UIBezierPath + let path: CGPath let scale: CGFloat let alpha: CGFloat - init(size: CGSize, path: UIBezierPath, scale: CGFloat, alpha: CGFloat) { + init(size: CGSize, path: CGPath, scale: CGFloat, alpha: CGFloat) { self.size = size self.path = path self.scale = scale @@ -564,7 +577,7 @@ private class VoiceChatActionButtonBackgroundNode: ASDisplayNode { if !self.isCurrentlyInHierarchy { animate = false } - + if animate { let animator: ConstantDisplayLinkAnimator if let current = self.animator { @@ -588,7 +601,8 @@ private class VoiceChatActionButtonBackgroundNode: ASDisplayNode { override public func drawParameters(forAsyncLayer layer: _ASDisplayLayer) -> NSObjectProtocol? { let timestamp = CACurrentMediaTime() - return VoiceChatActionButtonBackgroundNodeDrawingState(timestamp: timestamp, state: self.state.drawingState(), simplified: self.simplified, gradientMovement: self.gradientMovement, transition: self.transition?.drawingTransitionState(time: timestamp)) + let transitionState = self.transition?.drawingTransitionState(time: timestamp) + return VoiceChatActionButtonBackgroundNodeDrawingState(timestamp: timestamp, state: self.state.drawingState(transition: transitionState), simplified: self.simplified, gradientMovement: self.gradientMovement, transition: transitionState) } @objc override public class func draw(_ bounds: CGRect, withParameters parameters: Any?, isCancelled: () -> Bool, isRasterizing: Bool) { @@ -674,16 +688,7 @@ private class VoiceChatActionButtonBackgroundNode: ASDisplayNode { if let blobsState = parameters.state as? VoiceChatActionButtonBackgroundNodeBlobState { for blob in blobsState.blobs { - let uiPath = blob.path - let offset = (bounds.size.width - blob.size.width) / 2.0 - let toOrigin = CGAffineTransform(translationX: -bounds.size.width / 2.0 + offset, y: -bounds.size.height / 2.0 + offset) - let fromOrigin = CGAffineTransform(translationX: bounds.size.width / 2.0, y: bounds.size.height / 2.0) - - uiPath.apply(toOrigin) - uiPath.apply(CGAffineTransform(scaleX: blob.scale * appearanceProgress, y: blob.scale * appearanceProgress)) - uiPath.apply(fromOrigin) - - context.addPath(uiPath.cgPath) + context.addPath(blob.path) context.clip() context.setAlpha(blob.alpha) diff --git a/submodules/TelegramCallsUI/Sources/VoiceChatController.swift b/submodules/TelegramCallsUI/Sources/VoiceChatController.swift index 26a1a1a5dc..5066fd022d 100644 --- a/submodules/TelegramCallsUI/Sources/VoiceChatController.swift +++ b/submodules/TelegramCallsUI/Sources/VoiceChatController.swift @@ -915,7 +915,7 @@ public final class VoiceChatController: ViewController { } self.actionButton.isUserInteractionEnabled = actionButtonEnabled - self.actionButton.update(size: centralButtonSize, buttonSize: CGSize(width: 144.0, height: 144.0), state: actionButtonState, title: actionButtonTitle, subtitle: actionButtonSubtitle, simplified: layout.size.width < 330.0, animated: true) + self.actionButton.update(size: centralButtonSize, buttonSize: CGSize(width: 144.0, height: 144.0), state: actionButtonState, title: actionButtonTitle, subtitle: actionButtonSubtitle, simplified: layout.size.width < 330.0 || layout.deviceMetrics.type == .tablet, animated: true) transition.updateFrame(node: self.actionButton, frame: actionButtonFrame) var audioMode: CallControllerButtonsSpeakerMode = .none