fix(ios): fix PiP callback (#3601)

This commit is contained in:
Gaëtan Kueny 2024-03-26 14:10:31 +01:00 committed by GitHub
parent c9a75f3cde
commit bb9e7eb5a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 11 deletions

View File

@ -6,27 +6,33 @@ import React
#if os(iOS)
class RCTPictureInPicture: NSObject, AVPictureInPictureControllerDelegate {
private var _onPictureInPictureStatusChanged: (() -> Void)?
private var _onPictureInPictureEnter: (() -> Void)?
private var _onPictureInPictureExit: (() -> Void)?
private var _onRestoreUserInterfaceForPictureInPictureStop: (() -> Void)?
private var _restoreUserInterfaceForPIPStopCompletionHandler: ((Bool) -> Void)?
private var _pipController: AVPictureInPictureController?
private var _isActive = false
init(_ onPictureInPictureStatusChanged: (() -> Void)? = nil, _ onRestoreUserInterfaceForPictureInPictureStop: (() -> Void)? = nil) {
_onPictureInPictureStatusChanged = onPictureInPictureStatusChanged
init(
_ onPictureInPictureEnter: (() -> Void)? = nil,
_ onPictureInPictureExit: (() -> Void)? = nil,
_ onRestoreUserInterfaceForPictureInPictureStop: (() -> Void)? = nil
) {
_onPictureInPictureEnter = onPictureInPictureEnter
_onPictureInPictureExit = onPictureInPictureExit
_onRestoreUserInterfaceForPictureInPictureStop = onRestoreUserInterfaceForPictureInPictureStop
}
func pictureInPictureControllerDidStartPictureInPicture(_: AVPictureInPictureController) {
guard let _onPictureInPictureStatusChanged else { return }
guard let _onPictureInPictureEnter else { return }
_onPictureInPictureStatusChanged()
_onPictureInPictureEnter()
}
func pictureInPictureControllerDidStopPictureInPicture(_: AVPictureInPictureController) {
guard let _onPictureInPictureStatusChanged else { return }
guard let _onPictureInPictureExit else { return }
_onPictureInPictureStatusChanged()
_onPictureInPictureExit()
}
func pictureInPictureController(

View File

@ -120,12 +120,12 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
@objc var onTextTrackDataChanged: RCTDirectEventBlock?
@objc
func _onPictureInPictureStatusChanged() {
func _onPictureInPictureEnter() {
onPictureInPictureStatusChanged?(["isActive": NSNumber(value: true)])
}
@objc
func _onRestoreUserInterfaceForPictureInPictureStop() {
func _onPictureInPictureExit() {
onPictureInPictureStatusChanged?(["isActive": NSNumber(value: false)])
}
@ -143,9 +143,11 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
#if os(iOS)
_pip = RCTPictureInPicture({ [weak self] in
self?._onPictureInPictureStatusChanged()
self?._onPictureInPictureEnter()
}, { [weak self] in
self?._onRestoreUserInterfaceForPictureInPictureStop()
self?._onPictureInPictureExit()
}, { [weak self] in
self?.onRestoreUserInterfaceForPictureInPictureStop?([:])
})
#endif