diff --git a/Riot/Managers/Call/PiPAnimator.swift b/Riot/Managers/Call/PiPAnimator.swift index 46171be6d..9d770bada 100644 --- a/Riot/Managers/Call/PiPAnimator.swift +++ b/Riot/Managers/Call/PiPAnimator.swift @@ -52,6 +52,10 @@ class PiPAnimator: NSObject { return } + if let pipable = fromVC as? PictureInPicturable { + pipable.willEnterPiP?() + } + fromVC.willMove(toParent: nil) // TODO: find a way to call this at the end of animation context.completeTransition(true) @@ -75,7 +79,7 @@ class PiPAnimator: NSObject { animator.addCompletion { (position) in if let pipable = fromVC as? PictureInPicturable { - pipable.enterPiP?() + pipable.didEnterPiP?() } fromVC.dismiss(animated: false, completion: nil) } @@ -89,8 +93,16 @@ class PiPAnimator: NSObject { return } - guard let toVC = context.viewController(forKey: .to), - let snapshot = toVC.view.snapshotView(afterScreenUpdates: true) else { + guard let toVC = context.viewController(forKey: .to) else { + context.completeTransition(false) + return + } + + if let pipable = toVC as? PictureInPicturable { + pipable.willExitPiP?() + } + + guard let snapshot = toVC.view.snapshotView(afterScreenUpdates: true) else { context.completeTransition(false) return } @@ -122,7 +134,7 @@ class PiPAnimator: NSObject { snapshot.removeFromSuperview() if let pipable = toVC as? PictureInPicturable { - pipable.exitPiP?() + pipable.didExitPiP?() } context.completeTransition(!context.transitionWasCancelled) diff --git a/Riot/Managers/Call/PictureInPicturable.swift b/Riot/Managers/Call/PictureInPicturable.swift index b8ee9ae05..c37a904e8 100644 --- a/Riot/Managers/Call/PictureInPicturable.swift +++ b/Riot/Managers/Call/PictureInPicturable.swift @@ -18,7 +18,10 @@ import Foundation @objc protocol PictureInPicturable { - @objc optional func enterPiP() - @objc optional func exitPiP() + @objc optional func willEnterPiP() + @objc optional func didEnterPiP() + + @objc optional func willExitPiP() + @objc optional func didExitPiP() } diff --git a/Riot/Modules/Call/CallViewController.m b/Riot/Modules/Call/CallViewController.m index e877b9303..51b3a09e1 100644 --- a/Riot/Modules/Call/CallViewController.m +++ b/Riot/Modules/Call/CallViewController.m @@ -689,12 +689,17 @@ #pragma mark - PictureInPicturable -- (void)enterPiP +- (void)didEnterPiP { self.inPiP = YES; } -- (void)exitPiP +- (void)willExitPiP +{ + self.pipViewContainer.hidden = YES; +} + +- (void)didExitPiP { self.inPiP = NO; } diff --git a/Riot/Modules/Integrations/Widgets/Jitsi/JitsiViewController.m b/Riot/Modules/Integrations/Widgets/Jitsi/JitsiViewController.m index 393f757ab..a07a4ede3 100644 --- a/Riot/Modules/Integrations/Widgets/Jitsi/JitsiViewController.m +++ b/Riot/Modules/Integrations/Widgets/Jitsi/JitsiViewController.m @@ -346,7 +346,7 @@ static NSString * _Nonnull kJitsiFeatureFlagChatEnabled = @"chat.enabled"; #pragma mark - PictureInPicturable -- (void)enterPiP +- (void)didEnterPiP { self.overlayViews = [self overlayViewsIn:self.view]; for (UIView *view in self.overlayViews) @@ -355,7 +355,7 @@ static NSString * _Nonnull kJitsiFeatureFlagChatEnabled = @"chat.enabled"; } } -- (void)exitPiP +- (void)didExitPiP { for (UIView *view in self.overlayViews) {