Limit available controls layout

This commit is contained in:
Arkadiusz Fal 2022-08-29 14:41:21 +02:00
parent 8ac71a24c4
commit 95296b34b5
2 changed files with 36 additions and 3 deletions

View File

@ -1,5 +1,8 @@
import Defaults
import Foundation
#if os(iOS)
import UIKit
#endif
enum PlayerControlsLayout: String, CaseIterable, Defaults.Serializable {
case tvRegular
@ -9,6 +12,36 @@ enum PlayerControlsLayout: String, CaseIterable, Defaults.Serializable {
case small
case smaller
var available: Bool {
var isATV = false
var isIPad = false
#if os(tvOS)
isATV = true
#endif
#if os(iOS)
isIPad = UIDevice.current.userInterfaceIdiom == .pad
#endif
switch self {
case .tvRegular:
return isATV
case .veryLarge:
#if os(macOS)
return true
#else
return isIPad
#endif
case .large:
return true
case .medium:
return true
case .small:
return true
case .smaller:
return true
}
}
var description: String {
switch self {
case .tvRegular:

View File

@ -197,13 +197,13 @@ struct PlayerSettings: View {
@ViewBuilder private var controlsLayoutFooter: some View {
#if os(iOS)
Text("Large and bigger layouts are not suitable for all devices and using them may cause controls not to fit on the screen.")
Text("Large layout is not suitable for all devices and using it may cause controls not to fit on the screen.")
#endif
}
private var playerControlsLayoutPicker: some View {
Picker("Regular Size", selection: $playerControlsLayout) {
ForEach(PlayerControlsLayout.allCases, id: \.self) { layout in
ForEach(PlayerControlsLayout.allCases.filter(\.available), id: \.self) { layout in
Text(layout.description).tag(layout.rawValue)
}
}
@ -212,7 +212,7 @@ struct PlayerSettings: View {
private var fullScreenPlayerControlsLayoutPicker: some View {
Picker("Fullscreen Size", selection: $fullScreenPlayerControlsLayout) {
ForEach(PlayerControlsLayout.allCases, id: \.self) { layout in
ForEach(PlayerControlsLayout.allCases.filter(\.available), id: \.self) { layout in
Text(layout.description).tag(layout.rawValue)
}
}