react-native-video/ios/Video/RCTVideoPlayerViewController.swift
Krzysztof Moch f35727f30e
feat(ios): update the way to get keyWindow (#3448)
* feat(ios): update the way to get `keyWindow`

* lint
2023-12-28 12:58:25 +01:00

50 lines
1.5 KiB
Swift

import AVKit
class RCTVideoPlayerViewController: AVPlayerViewController {
weak var rctDelegate: RCTVideoPlayerViewControllerDelegate?
// Optional paramters
var preferredOrientation: String?
var autorotate: Bool?
func shouldAutorotate() -> Bool {
if autorotate! || preferredOrientation == nil || (preferredOrientation!.lowercased() == "all") {
return true
}
return false
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
rctDelegate?.videoPlayerViewControllerWillDismiss(playerViewController: self)
rctDelegate?.videoPlayerViewControllerDidDismiss(playerViewController: self)
}
#if !os(tvOS)
func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return .all
}
func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
if preferredOrientation?.lowercased() == "landscape" {
return .landscapeRight
} else if preferredOrientation?.lowercased() == "portrait" {
return .portrait
} else {
// default case
if #available(iOS 13, tvOS 13, *) {
return RCTVideoUtils.getCurrentWindow()?.windowScene?.interfaceOrientation ?? .unknown
} else {
#if !os(visionOS)
return UIApplication.shared.statusBarOrientation
#endif
}
}
}
#endif
}