From ad93eeaf3901a40c98e89c137afd8c45aee209c7 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Thu, 10 Jun 2021 17:42:29 +0300 Subject: [PATCH 1/2] Video Chat Improvements --- .../TelegramCallsUI/Sources/GroupVideoNode.swift | 7 +++++++ .../Sources/VoiceChatFullscreenParticipantItem.swift | 10 ++++++++-- .../Sources/VoiceChatMainStageNode.swift | 5 ++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/submodules/TelegramCallsUI/Sources/GroupVideoNode.swift b/submodules/TelegramCallsUI/Sources/GroupVideoNode.swift index 1f5163643e..0f379d911e 100644 --- a/submodules/TelegramCallsUI/Sources/GroupVideoNode.swift +++ b/submodules/TelegramCallsUI/Sources/GroupVideoNode.swift @@ -347,4 +347,11 @@ final class GroupVideoNode: ASDisplayNode { let transition: ContainedViewLayoutTransition = .immediate transition.updateTransformRotation(view: self.videoView.view, angle: angle) } + + var snapshotView: UIView? + func storeSnapshot() { + if self.frame.size.width == 180.0 { + self.snapshotView = self.view.snapshotView(afterScreenUpdates: false) + } + } } diff --git a/submodules/TelegramCallsUI/Sources/VoiceChatFullscreenParticipantItem.swift b/submodules/TelegramCallsUI/Sources/VoiceChatFullscreenParticipantItem.swift index e1574a3f2c..147b8f86fe 100644 --- a/submodules/TelegramCallsUI/Sources/VoiceChatFullscreenParticipantItem.swift +++ b/submodules/TelegramCallsUI/Sources/VoiceChatFullscreenParticipantItem.swift @@ -483,9 +483,12 @@ class VoiceChatFullscreenParticipantItemNode: ItemListRevealOptionsItemNode { let videoNode = item.getVideo() if let currentVideoNode = strongSelf.videoNode, currentVideoNode !== videoNode { if videoNode == nil { + let snapshotView = currentVideoNode.snapshotView if strongSelf.avatarNode.alpha.isZero { strongSelf.animatingSelection = true - strongSelf.videoContainerNode.layer.animateScale(from: videoContainerScale, to: 0.001, duration: appearanceDuration) + strongSelf.videoContainerNode.layer.animateScale(from: videoContainerScale, to: 0.001, duration: appearanceDuration, completion: { _ in + snapshotView?.removeFromSuperview() + }) strongSelf.avatarNode.layer.animateScale(from: 0.0, to: 1.0, duration: appearanceDuration, completion: { [weak self] _ in self?.animatingSelection = false }) @@ -494,6 +497,9 @@ class VoiceChatFullscreenParticipantItemNode: ItemListRevealOptionsItemNode { } if currentVideoNode.supernode === strongSelf.videoContainerNode { apperanceTransition.updateAlpha(node: currentVideoNode, alpha: 0.0) + } else if let snapshotView = snapshotView { + strongSelf.videoContainerNode.view.insertSubview(snapshotView, at: 0) + apperanceTransition.updateAlpha(layer: snapshotView.layer, alpha: 0.0) } apperanceTransition.updateAlpha(node: strongSelf.videoFadeNode, alpha: 0.0) apperanceTransition.updateAlpha(node: strongSelf.avatarNode, alpha: 1.0) @@ -873,7 +879,7 @@ class VoiceChatFullscreenParticipantItemNode: ItemListRevealOptionsItemNode { if !strongSelf.isExtracted && !strongSelf.animatingExtraction { if videoNode.supernode !== strongSelf.videoContainerNode { videoNode.clipsToBounds = true - strongSelf.videoContainerNode.addSubnode(videoNode) + strongSelf.videoContainerNode.insertSubnode(videoNode, at: 0) } videoNode.position = CGPoint(x: videoSize.width / 2.0, y: videoSize.height / 2.0) diff --git a/submodules/TelegramCallsUI/Sources/VoiceChatMainStageNode.swift b/submodules/TelegramCallsUI/Sources/VoiceChatMainStageNode.swift index d3972732fc..3bb7b990f2 100644 --- a/submodules/TelegramCallsUI/Sources/VoiceChatMainStageNode.swift +++ b/submodules/TelegramCallsUI/Sources/VoiceChatMainStageNode.swift @@ -830,7 +830,10 @@ final class VoiceChatMainStageNode: ASDisplayNode { return } - videoNode.isMainstageExclusive = isMyPeer + videoNode.isMainstageExclusive = isMyPeer && !isPresentation + if videoNode.isMainstageExclusive { + videoNode.storeSnapshot() + } videoNode.tapped = { [weak self] in guard let strongSelf = self else { return From 80f3f00f5bc8253498f99f8932c09797b5ad8f89 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Thu, 10 Jun 2021 17:54:16 +0300 Subject: [PATCH 2/2] Video Chat Improvements --- .../Sources/PresentationGroupCall.swift | 2 +- .../Sources/VoiceChatMainStageNode.swift | 23 ++++++++----------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/submodules/TelegramCallsUI/Sources/PresentationGroupCall.swift b/submodules/TelegramCallsUI/Sources/PresentationGroupCall.swift index 2017da3b47..f8b047ea8f 100644 --- a/submodules/TelegramCallsUI/Sources/PresentationGroupCall.swift +++ b/submodules/TelegramCallsUI/Sources/PresentationGroupCall.swift @@ -2568,7 +2568,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall { } private func updateLocalVideoState() { - self.participantsContext?.updateVideoState(peerId: self.joinAsPeerId, isVideoMuted: self.videoCapturer == nil, isVideoPaused: self.isVideoMuted) + self.participantsContext?.updateVideoState(peerId: self.joinAsPeerId, isVideoMuted: self.videoCapturer == nil, isVideoPaused: self.isVideoMuted, isPresentationPaused: false) } public func switchVideoCamera() { diff --git a/submodules/TelegramCallsUI/Sources/VoiceChatMainStageNode.swift b/submodules/TelegramCallsUI/Sources/VoiceChatMainStageNode.swift index 3bb7b990f2..23098fa29d 100644 --- a/submodules/TelegramCallsUI/Sources/VoiceChatMainStageNode.swift +++ b/submodules/TelegramCallsUI/Sources/VoiceChatMainStageNode.swift @@ -39,6 +39,7 @@ final class VoiceChatMainStageNode: ASDisplayNode { private let backgroundNode: ASDisplayNode private let topFadeNode: ASDisplayNode private let bottomFadeNode: ASDisplayNode + private let bottomGradientNode: ASDisplayNode private let bottomFillNode: ASDisplayNode private let headerNode: ASDisplayNode private let backButtonNode: HighlightableButtonNode @@ -106,7 +107,9 @@ final class VoiceChatMainStageNode: ASDisplayNode { } self.bottomFadeNode = ASDisplayNode() - self.bottomFadeNode.displaysAsynchronously = false + + self.bottomGradientNode = ASDisplayNode() + self.bottomGradientNode.displaysAsynchronously = false if let image = generateImage(CGSize(width: fadeHeight, height: fadeHeight), rotatedContext: { size, context in let bounds = CGRect(origin: CGPoint(), size: size) context.clear(bounds) @@ -116,7 +119,7 @@ final class VoiceChatMainStageNode: ASDisplayNode { let gradient = CGGradient(colorsSpace: deviceColorSpace, colors: colorsArray, locations: &locations)! context.drawLinearGradient(gradient, start: CGPoint(), end: CGPoint(x: 0.0, y: size.height), options: CGGradientDrawingOptions()) }) { - self.bottomFadeNode.backgroundColor = UIColor(patternImage: image) + self.bottomGradientNode.backgroundColor = UIColor(patternImage: image) } self.bottomFillNode = ASDisplayNode() @@ -200,7 +203,8 @@ final class VoiceChatMainStageNode: ASDisplayNode { self.addSubnode(self.backdropAvatarNode) self.addSubnode(self.topFadeNode) self.addSubnode(self.bottomFadeNode) - self.addSubnode(self.bottomFillNode) + self.bottomFadeNode.addSubnode(self.bottomGradientNode) + self.bottomFadeNode.addSubnode(self.bottomFillNode) self.addSubnode(self.audioLevelNode) self.addSubnode(self.avatarNode) self.addSubnode(self.titleNode) @@ -433,7 +437,6 @@ final class VoiceChatMainStageNode: ASDisplayNode { self.microphoneNode.alpha = 1.0 self.titleNode.alpha = 1.0 self.bottomFadeNode.alpha = 1.0 - self.bottomFillNode.alpha = 1.0 } alphaTransition.updateAlpha(node: self.topFadeNode, alpha: 0.0) alphaTransition.updateAlpha(node: self.titleNode, alpha: 0.0) @@ -766,7 +769,6 @@ final class VoiceChatMainStageNode: ASDisplayNode { private func setAvatarHidden(_ hidden: Bool) { self.topFadeNode.isHidden = !hidden self.bottomFadeNode.isHidden = !hidden - self.bottomFillNode.isHidden = !hidden self.avatarNode.isHidden = hidden self.audioLevelNode.isHidden = hidden } @@ -876,7 +878,6 @@ final class VoiceChatMainStageNode: ASDisplayNode { videoNode.alpha = 0.0 strongSelf.topFadeNode.isHidden = true strongSelf.bottomFadeNode.isHidden = true - strongSelf.bottomFillNode.isHidden = true } else if isMyPeer { videoNode.layer.removeAnimation(forKey: "opacity") videoNode.alpha = 1.0 @@ -910,11 +911,8 @@ final class VoiceChatMainStageNode: ASDisplayNode { if delayTransition { strongSelf.topFadeNode.isHidden = false strongSelf.bottomFadeNode.isHidden = false - strongSelf.bottomFillNode.isHidden = false strongSelf.topFadeNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.3) strongSelf.bottomFadeNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.3) - strongSelf.bottomFillNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.3) - strongSelf.avatarNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, removeOnCompletion: false) strongSelf.audioLevelNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, removeOnCompletion: false) } @@ -995,7 +993,6 @@ final class VoiceChatMainStageNode: ASDisplayNode { videoNode.updateIsBlurred(isBlurred: isPaused, light: true, animated: false) strongSelf.topFadeNode.isHidden = true strongSelf.bottomFadeNode.isHidden = true - strongSelf.bottomFillNode.isHidden = true if let videoNode = strongSelf.currentVideoNode { videoNode.alpha = 1.0 videoNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.3, completion: { [weak self] _ in @@ -1034,7 +1031,6 @@ final class VoiceChatMainStageNode: ASDisplayNode { transition.updateAlpha(node: self.titleNode, alpha: hidden ? 0.0 : 1.0, delay: delay) transition.updateAlpha(node: self.microphoneNode, alpha: hidden ? 0.0 : 1.0, delay: delay) transition.updateAlpha(node: self.bottomFadeNode, alpha: hidden ? 0.0 : 1.0, delay: delay) - transition.updateAlpha(node: self.bottomFillNode, alpha: hidden ? 0.0 : 1.0, delay: delay) } func update(size: CGSize, sideInset: CGFloat, bottomInset: CGFloat, isLandscape: Bool, isTablet: Bool, force: Bool = false, transition: ContainedViewLayoutTransition) { @@ -1084,8 +1080,9 @@ final class VoiceChatMainStageNode: ASDisplayNode { if size.height != tileHeight && size.width < size.height { totalFadeHeight += bottomInset } - transition.updateFrame(node: self.bottomFadeNode, frame: CGRect(x: 0.0, y: size.height - totalFadeHeight, width: size.width, height: fadeHeight)) - transition.updateFrame(node: self.bottomFillNode, frame: CGRect(x: 0.0, y: size.height - totalFadeHeight + fadeHeight, width: size.width, height: max(0.0, totalFadeHeight - fadeHeight))) + transition.updateFrame(node: self.bottomFadeNode, frame: CGRect(x: 0.0, y: size.height - totalFadeHeight, width: size.width, height: totalFadeHeight)) + transition.updateFrame(node: self.bottomGradientNode, frame: CGRect(x: 0.0, y: 0.0, width: size.width, height: fadeHeight)) + transition.updateFrame(node: self.bottomFillNode, frame: CGRect(x: 0.0, y: fadeHeight, width: size.width, height: max(0.0, totalFadeHeight - fadeHeight))) transition.updateFrame(node: self.topFadeNode, frame: CGRect(x: 0.0, y: 0.0, width: size.width, height: 50.0)) let backSize = self.backButtonNode.measure(CGSize(width: 320.0, height: 100.0))