diff --git a/submodules/TelegramCallsUI/Sources/Components/AnimatedCounterView.swift b/submodules/TelegramCallsUI/Sources/Components/AnimatedCounterView.swift index afb69f52a8..7074143ed9 100644 --- a/submodules/TelegramCallsUI/Sources/Components/AnimatedCounterView.swift +++ b/submodules/TelegramCallsUI/Sources/Components/AnimatedCounterView.swift @@ -37,6 +37,8 @@ public final class AnimatedCountView: UIView { countLabel.clipsToBounds = false subtitleLabel.textAlignment = .center self.clipsToBounds = false + + subtitleLabel.textColor = .white // self.backgroundColor = UIColor.white.withAlphaComponent(0.1) } diff --git a/submodules/TelegramCallsUI/Sources/Components/MediaStreamComponent.swift b/submodules/TelegramCallsUI/Sources/Components/MediaStreamComponent.swift index 4665bac49b..53769805f8 100644 --- a/submodules/TelegramCallsUI/Sources/Components/MediaStreamComponent.swift +++ b/submodules/TelegramCallsUI/Sources/Components/MediaStreamComponent.swift @@ -743,6 +743,7 @@ public final class _MediaStreamComponent: CombinedComponent { var videoSize: CGSize? private(set) var canManageCall: Bool = false + // TODO: also handle pictureInPicturePossible let isPictureInPictureSupported: Bool private(set) var callTitle: String? @@ -757,6 +758,10 @@ public final class _MediaStreamComponent: CombinedComponent { private var scheduledDismissUITimer: SwiftSignalKit.Timer? var videoStalled: Bool = false + var videoIsPlayable: Bool { + !videoStalled && hasVideo + } + let deactivatePictureInPictureIfVisible = StoredActionSlot(Void.self) var videoHiddenForPip = false @@ -1036,7 +1041,7 @@ public final class _MediaStreamComponent: CombinedComponent { // let height = context.availableSize.height var navigationRightItems: [AnyComponentWithIdentity] = [] // let contextView = context.view - if context.state.isPictureInPictureSupported, context.state.hasVideo { + if context.state.isPictureInPictureSupported, context.state.videoIsPlayable { navigationRightItems.append(AnyComponentWithIdentity(id: "pip", component: AnyComponent(Button( content: AnyComponent(ZStack([ AnyComponentWithIdentity(id: "b", component: AnyComponent(Circle( @@ -1305,7 +1310,7 @@ public final class _MediaStreamComponent: CombinedComponent { }) )*/, rightItems: navigationRightItems, - centerItem: AnyComponent(StreamTitleComponent(text: state.peerTitle, isRecording: state.recordingStartTimestamp != nil, isActive: context.state.hasVideo)) + centerItem: AnyComponent(StreamTitleComponent(text: state.peerTitle, isRecording: state.recordingStartTimestamp != nil, isActive: context.state.videoIsPlayable)) ) // let navigationBar = navigationBar.update( @@ -1476,7 +1481,7 @@ public final class _MediaStreamComponent: CombinedComponent { title: "expand" )), action: { - guard state.hasVideo else { + guard state.videoIsPlayable else { state.isFullscreen = false return } diff --git a/submodules/TelegramCallsUI/Sources/Components/MediaStreamVideoComponent.swift b/submodules/TelegramCallsUI/Sources/Components/MediaStreamVideoComponent.swift index ec41f4b8dd..e3b84da552 100644 --- a/submodules/TelegramCallsUI/Sources/Components/MediaStreamVideoComponent.swift +++ b/submodules/TelegramCallsUI/Sources/Components/MediaStreamVideoComponent.swift @@ -207,6 +207,9 @@ final class _MediaStreamVideoComponent: Component { videoView.alpha = 1 } if let sampleBufferVideoView = videoView as? SampleBufferVideoRenderingView { + sampleBufferVideoView.sampleBufferLayer.masksToBounds = true + sampleBufferVideoView.sampleBufferLayer.cornerRadius = 20 + if #available(iOS 13.0, *) { sampleBufferVideoView.sampleBufferLayer.preventsDisplaySleepDuringVideoPlayback = true } @@ -249,6 +252,8 @@ final class _MediaStreamVideoComponent: Component { } return delegate }())) + pictureInPictureController?.playerLayer.masksToBounds = false + pictureInPictureController?.playerLayer.cornerRadius = 30 } else if AVPictureInPictureController.isPictureInPictureSupported() { // TODO: support PiP for iOS < 15.0 // sampleBufferVideoView.sampleBufferLayer @@ -473,8 +478,15 @@ final class _MediaStreamVideoComponent: Component { } func pictureInPictureControllerWillStartPictureInPicture(_ pictureInPictureController: AVPictureInPictureController) { - videoView?.alpha = 0 - videoBlurView?.alpha = 0 + DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { + self.videoView?.alpha = 0 + } + UIView.animate(withDuration: 0.3) { [self] in + videoBlurView?.alpha = 0 + } + // TODO: make safe + UIApplication.shared.windows.first?/*(where: { $0.layer !== (UIApplication.shared.connectedScenes.first as? UIWindowScene)?.keyWindow?.layer })?*/.layer.cornerRadius = 10// (where: { !($0 is NativeWindow)*/ }) + UIApplication.shared.windows.first?.layer.masksToBounds = true } public func pictureInPictureController(_ pictureInPictureController: AVPictureInPictureController, restoreUserInterfaceForPictureInPictureStopWithCompletionHandler completionHandler: @escaping (Bool) -> Void) { @@ -498,11 +510,17 @@ final class _MediaStreamVideoComponent: Component { } else { self.component?.pictureInPictureClosed() } + // TODO: extract precise animation or observe window changes + DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { + self.videoView?.alpha = 1 + } + UIView.animate(withDuration: 0.3) { [self] in + self.videoBlurView?.alpha = 1 + } } func pictureInPictureControllerDidStopPictureInPicture(_ pictureInPictureController: AVPictureInPictureController) { self.videoView?.alpha = 1 - self.videoBlurView?.alpha = 1 self.state?.updated(transition: .immediate) } }