mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-16 19:30:29 +00:00
Fixing PiP transition corner radius and flickering
This commit is contained in:
parent
96876f1611
commit
a688d65873
@ -37,6 +37,8 @@ public final class AnimatedCountView: UIView {
|
|||||||
countLabel.clipsToBounds = false
|
countLabel.clipsToBounds = false
|
||||||
subtitleLabel.textAlignment = .center
|
subtitleLabel.textAlignment = .center
|
||||||
self.clipsToBounds = false
|
self.clipsToBounds = false
|
||||||
|
|
||||||
|
subtitleLabel.textColor = .white
|
||||||
// self.backgroundColor = UIColor.white.withAlphaComponent(0.1)
|
// self.backgroundColor = UIColor.white.withAlphaComponent(0.1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -743,6 +743,7 @@ public final class _MediaStreamComponent: CombinedComponent {
|
|||||||
var videoSize: CGSize?
|
var videoSize: CGSize?
|
||||||
|
|
||||||
private(set) var canManageCall: Bool = false
|
private(set) var canManageCall: Bool = false
|
||||||
|
// TODO: also handle pictureInPicturePossible
|
||||||
let isPictureInPictureSupported: Bool
|
let isPictureInPictureSupported: Bool
|
||||||
|
|
||||||
private(set) var callTitle: String?
|
private(set) var callTitle: String?
|
||||||
@ -757,6 +758,10 @@ public final class _MediaStreamComponent: CombinedComponent {
|
|||||||
private var scheduledDismissUITimer: SwiftSignalKit.Timer?
|
private var scheduledDismissUITimer: SwiftSignalKit.Timer?
|
||||||
var videoStalled: Bool = false
|
var videoStalled: Bool = false
|
||||||
|
|
||||||
|
var videoIsPlayable: Bool {
|
||||||
|
!videoStalled && hasVideo
|
||||||
|
}
|
||||||
|
|
||||||
let deactivatePictureInPictureIfVisible = StoredActionSlot(Void.self)
|
let deactivatePictureInPictureIfVisible = StoredActionSlot(Void.self)
|
||||||
|
|
||||||
var videoHiddenForPip = false
|
var videoHiddenForPip = false
|
||||||
@ -1036,7 +1041,7 @@ public final class _MediaStreamComponent: CombinedComponent {
|
|||||||
// let height = context.availableSize.height
|
// let height = context.availableSize.height
|
||||||
var navigationRightItems: [AnyComponentWithIdentity<Empty>] = []
|
var navigationRightItems: [AnyComponentWithIdentity<Empty>] = []
|
||||||
// let contextView = context.view
|
// 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(
|
navigationRightItems.append(AnyComponentWithIdentity(id: "pip", component: AnyComponent(Button(
|
||||||
content: AnyComponent(ZStack([
|
content: AnyComponent(ZStack([
|
||||||
AnyComponentWithIdentity(id: "b", component: AnyComponent(Circle(
|
AnyComponentWithIdentity(id: "b", component: AnyComponent(Circle(
|
||||||
@ -1305,7 +1310,7 @@ public final class _MediaStreamComponent: CombinedComponent {
|
|||||||
})
|
})
|
||||||
)*/,
|
)*/,
|
||||||
rightItems: navigationRightItems,
|
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(
|
// let navigationBar = navigationBar.update(
|
||||||
@ -1476,7 +1481,7 @@ public final class _MediaStreamComponent: CombinedComponent {
|
|||||||
title: "expand"
|
title: "expand"
|
||||||
)),
|
)),
|
||||||
action: {
|
action: {
|
||||||
guard state.hasVideo else {
|
guard state.videoIsPlayable else {
|
||||||
state.isFullscreen = false
|
state.isFullscreen = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -207,6 +207,9 @@ final class _MediaStreamVideoComponent: Component {
|
|||||||
videoView.alpha = 1
|
videoView.alpha = 1
|
||||||
}
|
}
|
||||||
if let sampleBufferVideoView = videoView as? SampleBufferVideoRenderingView {
|
if let sampleBufferVideoView = videoView as? SampleBufferVideoRenderingView {
|
||||||
|
sampleBufferVideoView.sampleBufferLayer.masksToBounds = true
|
||||||
|
sampleBufferVideoView.sampleBufferLayer.cornerRadius = 20
|
||||||
|
|
||||||
if #available(iOS 13.0, *) {
|
if #available(iOS 13.0, *) {
|
||||||
sampleBufferVideoView.sampleBufferLayer.preventsDisplaySleepDuringVideoPlayback = true
|
sampleBufferVideoView.sampleBufferLayer.preventsDisplaySleepDuringVideoPlayback = true
|
||||||
}
|
}
|
||||||
@ -249,6 +252,8 @@ final class _MediaStreamVideoComponent: Component {
|
|||||||
}
|
}
|
||||||
return delegate
|
return delegate
|
||||||
}()))
|
}()))
|
||||||
|
pictureInPictureController?.playerLayer.masksToBounds = false
|
||||||
|
pictureInPictureController?.playerLayer.cornerRadius = 30
|
||||||
} else if AVPictureInPictureController.isPictureInPictureSupported() {
|
} else if AVPictureInPictureController.isPictureInPictureSupported() {
|
||||||
// TODO: support PiP for iOS < 15.0
|
// TODO: support PiP for iOS < 15.0
|
||||||
// sampleBufferVideoView.sampleBufferLayer
|
// sampleBufferVideoView.sampleBufferLayer
|
||||||
@ -473,8 +478,15 @@ final class _MediaStreamVideoComponent: Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func pictureInPictureControllerWillStartPictureInPicture(_ pictureInPictureController: AVPictureInPictureController) {
|
func pictureInPictureControllerWillStartPictureInPicture(_ pictureInPictureController: AVPictureInPictureController) {
|
||||||
videoView?.alpha = 0
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
||||||
videoBlurView?.alpha = 0
|
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) {
|
public func pictureInPictureController(_ pictureInPictureController: AVPictureInPictureController, restoreUserInterfaceForPictureInPictureStopWithCompletionHandler completionHandler: @escaping (Bool) -> Void) {
|
||||||
@ -498,11 +510,17 @@ final class _MediaStreamVideoComponent: Component {
|
|||||||
} else {
|
} else {
|
||||||
self.component?.pictureInPictureClosed()
|
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) {
|
func pictureInPictureControllerDidStopPictureInPicture(_ pictureInPictureController: AVPictureInPictureController) {
|
||||||
self.videoView?.alpha = 1
|
self.videoView?.alpha = 1
|
||||||
self.videoBlurView?.alpha = 1
|
|
||||||
self.state?.updated(transition: .immediate)
|
self.state?.updated(transition: .immediate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user