From a23580635fea74c1cb321a6b784d49267d5632ae Mon Sep 17 00:00:00 2001 From: Ilya Yelagov Date: Sun, 27 Nov 2022 17:56:18 +0400 Subject: [PATCH] Fixing counter animation --- .../Components/MediaStreamComponent.swift | 2 +- .../MediaStreamVideoComponent.swift | 4 +- .../Components/StreamSheetComponent.swift | 91 ++++++++++++++----- 3 files changed, 71 insertions(+), 26 deletions(-) diff --git a/submodules/TelegramCallsUI/Sources/Components/MediaStreamComponent.swift b/submodules/TelegramCallsUI/Sources/Components/MediaStreamComponent.swift index b53bcf8d51..981c5e33b9 100644 --- a/submodules/TelegramCallsUI/Sources/Components/MediaStreamComponent.swift +++ b/submodules/TelegramCallsUI/Sources/Components/MediaStreamComponent.swift @@ -822,7 +822,7 @@ public final class _MediaStreamComponent: CombinedComponent { if #available(iOSApplicationExtension 15.0, iOS 15.0, *), AVPictureInPictureController.isPictureInPictureSupported() { self.isPictureInPictureSupported = true } else { - self.isPictureInPictureSupported = true + self.isPictureInPictureSupported = AVPictureInPictureController.isPictureInPictureSupported() } super.init() diff --git a/submodules/TelegramCallsUI/Sources/Components/MediaStreamVideoComponent.swift b/submodules/TelegramCallsUI/Sources/Components/MediaStreamVideoComponent.swift index 7048b8ad93..eca99c62b5 100644 --- a/submodules/TelegramCallsUI/Sources/Components/MediaStreamVideoComponent.swift +++ b/submodules/TelegramCallsUI/Sources/Components/MediaStreamVideoComponent.swift @@ -214,7 +214,7 @@ final class _MediaStreamVideoComponent: Component { return false } } - let pictureInPictureController: AVPictureInPictureController? + var pictureInPictureController: AVPictureInPictureController? = nil if #available(iOS 15.0, *) { pictureInPictureController = AVPictureInPictureController(contentSource: AVPictureInPictureController.ContentSource(sampleBufferDisplayLayer: sampleBufferVideoView.sampleBufferLayer, playbackDelegate: { let delegate = PlaybackDelegateImpl() @@ -225,7 +225,7 @@ final class _MediaStreamVideoComponent: Component { } return delegate }())) - } else { + } else if AVPictureInPictureController.isPictureInPictureSupported() { // TODO: support PiP for iOS < 15.0 // sampleBufferVideoView.sampleBufferLayer pictureInPictureController = AVPictureInPictureController.init(playerLayer: AVPlayerLayer(player: AVPlayer())) diff --git a/submodules/TelegramCallsUI/Sources/Components/StreamSheetComponent.swift b/submodules/TelegramCallsUI/Sources/Components/StreamSheetComponent.swift index 4de232af33..30d97bc3c1 100644 --- a/submodules/TelegramCallsUI/Sources/Components/StreamSheetComponent.swift +++ b/submodules/TelegramCallsUI/Sources/Components/StreamSheetComponent.swift @@ -176,11 +176,12 @@ final class StreamSheetComponent: CombinedComponent { (context.view as? StreamSheetComponent.View)?.overlayComponentsFrames.append(.init(x: 0, y: topOffset, width: topItem.size.width, height: topItem.size.height)) } + let videoHeight = (availableWidth - 32) / 16 * 9 let animatedParticipantsVisible = context.component.participantsCount != -1 - if animatedParticipantsVisible { - // let videoHeight = availableWidth / 2 + if true { context.add(viewerCounter - .position(CGPoint(x: context.availableSize.width / 2, y: topOffset + 50 + 200 + 40 + 30)) + .position(CGPoint(x: context.availableSize.width / 2, y: topOffset + 50 + videoHeight + 40 + 30)) + .opacity(animatedParticipantsVisible ? 1 : 0) ) } @@ -533,15 +534,27 @@ class AnimatedCountLabel: UILabel { required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } - + var itemWidth: CGFloat { 36 } override func layoutSubviews() { super.layoutSubviews() let interItemSpacing: CGFloat = 0 - let countWidth = chars.reduce(0) { $0 + $1.frame.width + interItemSpacing } - interItemSpacing + let countWidth = chars.reduce(0) { + if $1.attributedText?.string == "," { + return $0 + 12 + } + return $0 + itemWidth + interItemSpacing + } - interItemSpacing containerView.frame = .init(x: bounds.midX - countWidth / 2, y: 0, width: countWidth, height: bounds.height) chars.enumerated().forEach { (index, char) in - char.frame.origin.x = CGFloat(chars.count - 1 - index) * (40 + interItemSpacing) + let offset = chars[0..