Skip to content

Commit

Permalink
Merge pull request #6 from pfleigo/picture-in-picture
Browse files Browse the repository at this point in the history
fix: add own fullscreendiddismiss observer
  • Loading branch information
pfleigo authored Apr 2, 2023
2 parents d87054f + acbdcee commit 7fe9b6f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions ios/Video/RCTPlayerDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ class RCTPlayerDelegate: NSObject, AVPlayerViewControllerDelegate {
private var _onPictureInPictureStatusChanged: RCTDirectEventBlock?
private var _onVideoFullscreenPlayerWillPresent: RCTDirectEventBlock?
private var _onVideoFullscreenPlayerWillDismiss: RCTDirectEventBlock?
private var _onVideoFullscreenPlayerDidDismiss: RCTDirectEventBlock?

init(_ onPictureInPictureStatusChanged: RCTDirectEventBlock?, _ onVideoFullscreenPlayerWillPresent: RCTDirectEventBlock?, _ onVideoFullscreenPlayerWillDismiss: RCTDirectEventBlock?) {
init(_ onPictureInPictureStatusChanged: RCTDirectEventBlock?, _ onVideoFullscreenPlayerWillPresent: RCTDirectEventBlock?, _ onVideoFullscreenPlayerWillDismiss: RCTDirectEventBlock?, _ onVideoFullscreenPlayerDidDismiss: RCTDirectEventBlock?) {
_onPictureInPictureStatusChanged = onPictureInPictureStatusChanged
_onVideoFullscreenPlayerWillPresent = onVideoFullscreenPlayerWillPresent
_onVideoFullscreenPlayerWillDismiss = onVideoFullscreenPlayerWillDismiss
_onVideoFullscreenPlayerDidDismiss = onVideoFullscreenPlayerDidDismiss
}

func playerViewControllerDidStartPictureInPicture(_ playerViewController: AVPlayerViewController) {
Expand All @@ -36,7 +38,10 @@ class RCTPlayerDelegate: NSObject, AVPlayerViewControllerDelegate {

}

func playerViewController(_ playerViewController: AVPlayerViewController, willEndFullScreenPresentationWithAnimationCoordinator: UIViewControllerTransitionCoordinator) {
func playerViewController(_ playerViewController: AVPlayerViewController, willEndFullScreenPresentationWithAnimationCoordinator coordinator: UIViewControllerTransitionCoordinator) {
coordinator.animate(alongsideTransition: nil, completion: { _ in
self._onVideoFullscreenPlayerDidDismiss?([:])
})

_onVideoFullscreenPlayerWillDismiss?([:])

Expand Down
6 changes: 3 additions & 3 deletions ios/Video/RCTVideo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
self.removePlayerLayer()
self.usePlayerViewController()
if (_playerViewController !== nil) {
_playerDelegate = RCTPlayerDelegate(self.onPictureInPictureStatusChanged, self.onVideoFullscreenPlayerWillPresent, self.onVideoFullscreenPlayerWillDismiss)
_playerDelegate = RCTPlayerDelegate(self.onPictureInPictureStatusChanged, self.onVideoFullscreenPlayerWillPresent, self.onVideoFullscreenPlayerWillDismiss, self.onVideoFullscreenPlayerDidDismiss)
_playerViewController!.delegate = _playerDelegate
}
}
Expand Down Expand Up @@ -780,8 +780,8 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
_playerViewController = nil
_playerObserver.playerViewController = nil
self.applyModifiers()

onVideoFullscreenPlayerDidDismiss?(["target": reactTag as Any])
// Moved to RCTPlayerDelegate
// onVideoFullscreenPlayerDidDismiss?(["target": reactTag as Any])
}
}

Expand Down

0 comments on commit 7fe9b6f

Please sign in to comment.