diff --git a/ios/Video/Features/RCTPictureInPicture.swift b/ios/Video/Features/RCTPictureInPicture.swift index 0ecc37b3..6f5ef79e 100644 --- a/ios/Video/Features/RCTPictureInPicture.swift +++ b/ios/Video/Features/RCTPictureInPicture.swift @@ -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( diff --git a/ios/Video/RCTVideo.swift b/ios/Video/RCTVideo.swift index efad295f..4738103c 100644 --- a/ios/Video/RCTVideo.swift +++ b/ios/Video/RCTVideo.swift @@ -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