diff --git a/Shared/Player/PlayerBackendView.swift b/Shared/Player/PlayerBackendView.swift index 92808ba7..daf7f846 100644 --- a/Shared/Player/PlayerBackendView.swift +++ b/Shared/Player/PlayerBackendView.swift @@ -68,9 +68,9 @@ struct PlayerBackendView: View { guard fullScreenLayout else { return 0 } if UIDevice.current.userInterfaceIdiom != .pad { - return verticalSizeClass == .compact ? safeAreaInsets.top : 0 + return verticalSizeClass == .compact ? SafeArea.insets.top : 0 } else { - return safeAreaInsets.top.isZero ? safeAreaInsets.bottom : safeAreaInsets.top + return SafeArea.insets.top.isZero ? SafeArea.insets.bottom : SafeArea.insets.top } } @@ -78,15 +78,11 @@ struct PlayerBackendView: View { guard fullScreenLayout else { return 0 } if UIDevice.current.userInterfaceIdiom != .pad { - return fullScreenLayout && verticalSizeClass == .compact ? safeAreaInsets.bottom : 0 + return fullScreenLayout && verticalSizeClass == .compact ? SafeArea.insets.bottom : 0 } else { - return fullScreenLayout ? safeAreaInsets.bottom : 0 + return fullScreenLayout ? SafeArea.insets.bottom : 0 } } - - var safeAreaInsets: UIEdgeInsets { - UIApplication.shared.windows.first?.safeAreaInsets ?? .init() - } #endif } diff --git a/Shared/Player/VideoPlayerView.swift b/Shared/Player/VideoPlayerView.swift index 5693ee7d..88079311 100644 --- a/Shared/Player/VideoPlayerView.swift +++ b/Shared/Player/VideoPlayerView.swift @@ -146,11 +146,11 @@ struct VideoPlayerView: View { #if os(iOS) var playerWidth: Double? { - fullScreenLayout ? (UIScreen.main.bounds.size.width - safeAreaInsets.left - safeAreaInsets.right) : nil + fullScreenLayout ? (UIScreen.main.bounds.size.width - SafeArea.insets.left - SafeArea.insets.right) : nil } var playerHeight: Double? { - fullScreenLayout ? UIScreen.main.bounds.size.height - (OrientationTracker.shared.currentInterfaceOrientation.isPortrait ? (safeAreaInsets.top + safeAreaInsets.bottom) : 0) : nil + fullScreenLayout ? UIScreen.main.bounds.size.height - (OrientationTracker.shared.currentInterfaceOrientation.isPortrait ? (SafeArea.insets.top + SafeArea.insets.bottom) : 0) : nil } var playerEdgesIgnoringSafeArea: Edge.Set { @@ -403,10 +403,6 @@ struct VideoPlayerView: View { } } - var safeAreaInsets: UIEdgeInsets { - UIApplication.shared.windows.first?.safeAreaInsets ?? .init() - } - private func configureOrientationUpdatesBasedOnAccelerometer() { if OrientationTracker.shared.currentInterfaceOrientation.isLandscape, Defaults[.enterFullscreenInLandscape], diff --git a/Yattee.xcodeproj/project.pbxproj b/Yattee.xcodeproj/project.pbxproj index 1d28c065..de5c223c 100644 --- a/Yattee.xcodeproj/project.pbxproj +++ b/Yattee.xcodeproj/project.pbxproj @@ -744,6 +744,7 @@ 37EBD8CA27AF26C200F1C24B /* MPVBackend.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37EBD8C927AF26C200F1C24B /* MPVBackend.swift */; }; 37EBD8CB27AF26C200F1C24B /* MPVBackend.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37EBD8C927AF26C200F1C24B /* MPVBackend.swift */; }; 37EBD8CC27AF26C200F1C24B /* MPVBackend.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37EBD8C927AF26C200F1C24B /* MPVBackend.swift */; }; + 37ECED56289FE166002BC2C9 /* SafeArea.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37ECED55289FE166002BC2C9 /* SafeArea.swift */; }; 37EF5C222739D37B00B03725 /* MenuModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37EF5C212739D37B00B03725 /* MenuModel.swift */; }; 37EF5C232739D37B00B03725 /* MenuModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37EF5C212739D37B00B03725 /* MenuModel.swift */; }; 37EF5C242739D37B00B03725 /* MenuModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37EF5C212739D37B00B03725 /* MenuModel.swift */; }; @@ -1203,6 +1204,7 @@ 37EBD8C327AF0DA800F1C24B /* PlayerBackend.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerBackend.swift; sourceTree = ""; }; 37EBD8C527AF26B300F1C24B /* AVPlayerBackend.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AVPlayerBackend.swift; sourceTree = ""; }; 37EBD8C927AF26C200F1C24B /* MPVBackend.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPVBackend.swift; sourceTree = ""; }; + 37ECED55289FE166002BC2C9 /* SafeArea.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SafeArea.swift; sourceTree = ""; }; 37EF5C212739D37B00B03725 /* MenuModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuModel.swift; sourceTree = ""; }; 37EF9A75275BEB8E0043B585 /* CommentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentView.swift; sourceTree = ""; }; 37F0F4E9286F397E00C06C2E /* SettingsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsModel.swift; sourceTree = ""; }; @@ -1804,6 +1806,7 @@ 37B4E802277D0A72004BF56A /* AppDelegate.swift */, 37B4E804277D0AB4004BF56A /* Orientation.swift */, 379B0252287A1CDF001015B5 /* OrientationTracker.swift */, + 37ECED55289FE166002BC2C9 /* SafeArea.swift */, 3784B23A272894DA00B09468 /* ShareSheet.swift */, 3749BF9227ADA142000480FF /* BridgingHeader.h */, 37992DC726CC50BC003D4C27 /* Info.plist */, @@ -2685,6 +2688,7 @@ buildActionMask = 2147483647; files = ( 374710052755291C00CE0F87 /* SearchField.swift in Sources */, + 37ECED56289FE166002BC2C9 /* SafeArea.swift in Sources */, 37CEE4BD2677B670005A1EFE /* SingleAssetStream.swift in Sources */, 37C2211D27ADA33300305B41 /* MPVViewController.swift in Sources */, 371B7E612759706A00D21217 /* CommentsView.swift in Sources */, diff --git a/iOS/SafeArea.swift b/iOS/SafeArea.swift new file mode 100644 index 00000000..98014f67 --- /dev/null +++ b/iOS/SafeArea.swift @@ -0,0 +1,15 @@ +import Foundation +import UIKit + +struct SafeArea { + static var insets: UIEdgeInsets { + let keyWindow = UIApplication.shared.connectedScenes + .filter { $0.activationState == .foregroundActive } + .compactMap { $0 as? UIWindowScene } + .first? + .windows + .first { $0.isKeyWindow } + + return keyWindow?.safeAreaInsets ?? .init() + } +}