fix(ios): fix PiP callback (#3601)
This commit is contained in:
parent
c9a75f3cde
commit
bb9e7eb5a5
@ -6,27 +6,33 @@ import React
|
|||||||
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
class RCTPictureInPicture: NSObject, AVPictureInPictureControllerDelegate {
|
class RCTPictureInPicture: NSObject, AVPictureInPictureControllerDelegate {
|
||||||
private var _onPictureInPictureStatusChanged: (() -> Void)?
|
private var _onPictureInPictureEnter: (() -> Void)?
|
||||||
|
private var _onPictureInPictureExit: (() -> Void)?
|
||||||
private var _onRestoreUserInterfaceForPictureInPictureStop: (() -> Void)?
|
private var _onRestoreUserInterfaceForPictureInPictureStop: (() -> Void)?
|
||||||
private var _restoreUserInterfaceForPIPStopCompletionHandler: ((Bool) -> Void)?
|
private var _restoreUserInterfaceForPIPStopCompletionHandler: ((Bool) -> Void)?
|
||||||
private var _pipController: AVPictureInPictureController?
|
private var _pipController: AVPictureInPictureController?
|
||||||
private var _isActive = false
|
private var _isActive = false
|
||||||
|
|
||||||
init(_ onPictureInPictureStatusChanged: (() -> Void)? = nil, _ onRestoreUserInterfaceForPictureInPictureStop: (() -> Void)? = nil) {
|
init(
|
||||||
_onPictureInPictureStatusChanged = onPictureInPictureStatusChanged
|
_ onPictureInPictureEnter: (() -> Void)? = nil,
|
||||||
|
_ onPictureInPictureExit: (() -> Void)? = nil,
|
||||||
|
_ onRestoreUserInterfaceForPictureInPictureStop: (() -> Void)? = nil
|
||||||
|
) {
|
||||||
|
_onPictureInPictureEnter = onPictureInPictureEnter
|
||||||
|
_onPictureInPictureExit = onPictureInPictureExit
|
||||||
_onRestoreUserInterfaceForPictureInPictureStop = onRestoreUserInterfaceForPictureInPictureStop
|
_onRestoreUserInterfaceForPictureInPictureStop = onRestoreUserInterfaceForPictureInPictureStop
|
||||||
}
|
}
|
||||||
|
|
||||||
func pictureInPictureControllerDidStartPictureInPicture(_: AVPictureInPictureController) {
|
func pictureInPictureControllerDidStartPictureInPicture(_: AVPictureInPictureController) {
|
||||||
guard let _onPictureInPictureStatusChanged else { return }
|
guard let _onPictureInPictureEnter else { return }
|
||||||
|
|
||||||
_onPictureInPictureStatusChanged()
|
_onPictureInPictureEnter()
|
||||||
}
|
}
|
||||||
|
|
||||||
func pictureInPictureControllerDidStopPictureInPicture(_: AVPictureInPictureController) {
|
func pictureInPictureControllerDidStopPictureInPicture(_: AVPictureInPictureController) {
|
||||||
guard let _onPictureInPictureStatusChanged else { return }
|
guard let _onPictureInPictureExit else { return }
|
||||||
|
|
||||||
_onPictureInPictureStatusChanged()
|
_onPictureInPictureExit()
|
||||||
}
|
}
|
||||||
|
|
||||||
func pictureInPictureController(
|
func pictureInPictureController(
|
||||||
|
@ -120,12 +120,12 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
@objc var onTextTrackDataChanged: RCTDirectEventBlock?
|
@objc var onTextTrackDataChanged: RCTDirectEventBlock?
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
func _onPictureInPictureStatusChanged() {
|
func _onPictureInPictureEnter() {
|
||||||
onPictureInPictureStatusChanged?(["isActive": NSNumber(value: true)])
|
onPictureInPictureStatusChanged?(["isActive": NSNumber(value: true)])
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
func _onRestoreUserInterfaceForPictureInPictureStop() {
|
func _onPictureInPictureExit() {
|
||||||
onPictureInPictureStatusChanged?(["isActive": NSNumber(value: false)])
|
onPictureInPictureStatusChanged?(["isActive": NSNumber(value: false)])
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,9 +143,11 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
_pip = RCTPictureInPicture({ [weak self] in
|
_pip = RCTPictureInPicture({ [weak self] in
|
||||||
self?._onPictureInPictureStatusChanged()
|
self?._onPictureInPictureEnter()
|
||||||
}, { [weak self] in
|
}, { [weak self] in
|
||||||
self?._onRestoreUserInterfaceForPictureInPictureStop()
|
self?._onPictureInPictureExit()
|
||||||
|
}, { [weak self] in
|
||||||
|
self?.onRestoreUserInterfaceForPictureInPictureStop?([:])
|
||||||
})
|
})
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user