Set full screen views background color based on color scheme on tvOS (fixes #30)

This commit is contained in:
Arkadiusz Fal 2021-12-05 18:09:25 +01:00
parent 5143c4f8ce
commit 941e6a909d
10 changed files with 31 additions and 13 deletions

View File

@ -10,8 +10,8 @@ extension Color {
static let secondaryBackground = Color(UIColor.secondarySystemBackground) static let secondaryBackground = Color(UIColor.secondarySystemBackground)
static let tertiaryBackground = Color(UIColor.tertiarySystemBackground) static let tertiaryBackground = Color(UIColor.tertiarySystemBackground)
#else #else
static let background = Color.black static func background(scheme: ColorScheme) -> Color {
static let secondaryBackground = Color.black scheme == .dark ? .black : .init(white: 0.8)
static let tertiaryBackground = Color.black }
#endif #endif
} }

View File

@ -7,6 +7,7 @@ struct AddToPlaylistView: View {
@State private var selectedPlaylistID: Playlist.ID = "" @State private var selectedPlaylistID: Playlist.ID = ""
@Environment(\.colorScheme) private var colorScheme
@Environment(\.presentationMode) private var presentationMode @Environment(\.presentationMode) private var presentationMode
@EnvironmentObject<PlaylistsModel> private var model @EnvironmentObject<PlaylistsModel> private var model
@ -37,7 +38,7 @@ struct AddToPlaylistView: View {
.padding(.vertical) .padding(.vertical)
#elseif os(tvOS) #elseif os(tvOS)
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity) .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
.background(Color.tertiaryBackground) .background(Color.background(scheme: colorScheme))
#else #else
.padding(.vertical) .padding(.vertical)
#endif #endif

View File

@ -10,6 +10,7 @@ struct PlaylistFormView: View {
@State private var valid = false @State private var valid = false
@State private var showingDeleteConfirmation = false @State private var showingDeleteConfirmation = false
@Environment(\.colorScheme) private var colorScheme
@Environment(\.presentationMode) private var presentationMode @Environment(\.presentationMode) private var presentationMode
@EnvironmentObject<AccountsModel> private var accounts @EnvironmentObject<AccountsModel> private var accounts
@ -77,7 +78,7 @@ struct PlaylistFormView: View {
.frame(maxWidth: 1000) .frame(maxWidth: 1000)
} }
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity) .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
.background(Color.tertiaryBackground) .background(Color.background(scheme: colorScheme))
#endif #endif
} }
.onChange(of: name) { _ in validate() } .onChange(of: name) { _ in validate() }

View File

@ -15,6 +15,7 @@ struct AccountForm: View {
@State private var validationError: String? @State private var validationError: String?
@State private var validationDebounce = Debounce() @State private var validationDebounce = Debounce()
@Environment(\.colorScheme) private var colorScheme
@Environment(\.presentationMode) private var presentationMode @Environment(\.presentationMode) private var presentationMode
var body: some View { var body: some View {
@ -30,7 +31,7 @@ struct AccountForm: View {
.padding(.vertical) .padding(.vertical)
#elseif os(tvOS) #elseif os(tvOS)
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity) .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
.background(Color.tertiaryBackground) .background(Color.background(scheme: colorScheme))
#else #else
.frame(width: 400, height: 145) .frame(width: 400, height: 145)
#endif #endif

View File

@ -13,6 +13,7 @@ struct InstanceForm: View {
@State private var validationError: String? @State private var validationError: String?
@State private var validationDebounce = Debounce() @State private var validationDebounce = Debounce()
@Environment(\.colorScheme) private var colorScheme
@Environment(\.presentationMode) private var presentationMode @Environment(\.presentationMode) private var presentationMode
var body: some View { var body: some View {
@ -32,7 +33,7 @@ struct InstanceForm: View {
.padding(.vertical) .padding(.vertical)
#elseif os(tvOS) #elseif os(tvOS)
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity) .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
.background(Color.tertiaryBackground) .background(Color.background(scheme: colorScheme))
#else #else
.frame(width: 400, height: 190) .frame(width: 400, height: 190)
#endif #endif

View File

@ -9,6 +9,8 @@ struct SettingsView: View {
} }
#endif #endif
@Environment(\.colorScheme) private var colorScheme
#if os(iOS) #if os(iOS)
@Environment(\.presentationMode) private var presentationMode @Environment(\.presentationMode) private var presentationMode
#endif #endif
@ -102,7 +104,7 @@ struct SettingsView: View {
InstanceForm(savedInstanceID: $savedFormInstanceID) InstanceForm(savedInstanceID: $savedFormInstanceID)
} }
#if os(tvOS) #if os(tvOS)
.background(Color.black) .background(Color.background(scheme: colorScheme))
#endif #endif
#endif #endif
} }

View File

@ -9,6 +9,8 @@ struct ChannelPlaylistView: View {
@StateObject private var store = Store<ChannelPlaylist>() @StateObject private var store = Store<ChannelPlaylist>()
@Environment(\.colorScheme) private var colorScheme
#if os(iOS) #if os(iOS)
@Environment(\.inNavigationView) private var inNavigationView @Environment(\.inNavigationView) private var inNavigationView
#endif #endif
@ -83,7 +85,7 @@ struct ChannelPlaylistView: View {
.navigationTitle(playlist.title) .navigationTitle(playlist.title)
#else #else
.background(Color.tertiaryBackground) .background(Color.background(scheme: colorScheme))
#endif #endif
} }

View File

@ -9,6 +9,7 @@ struct ChannelVideosView: View {
@StateObject private var store = Store<Channel>() @StateObject private var store = Store<Channel>()
@Environment(\.colorScheme) private var colorScheme
@Environment(\.presentationMode) private var presentationMode @Environment(\.presentationMode) private var presentationMode
@Environment(\.inNavigationView) private var inNavigationView @Environment(\.inNavigationView) private var inNavigationView
@ -105,8 +106,6 @@ struct ChannelVideosView: View {
} }
} }
} }
#else
.background(Color.tertiaryBackground)
#endif #endif
#if os(iOS) #if os(iOS)
.sheet(isPresented: $presentingShareSheet) { .sheet(isPresented: $presentingShareSheet) {
@ -126,6 +125,9 @@ struct ChannelVideosView: View {
return Group { return Group {
if #available(macOS 12.0, *) { if #available(macOS 12.0, *) {
content content
#if os(tvOS)
.background(Color.background(scheme: colorScheme))
#endif
#if !os(iOS) #if !os(iOS)
.focusScope(focusNamespace) .focusScope(focusNamespace)
#endif #endif

View File

@ -25,13 +25,19 @@ struct DetailBadge: View {
} }
struct DefaultStyleModifier: ViewModifier { struct DefaultStyleModifier: ViewModifier {
@Environment(\.colorScheme) private var colorScheme
func body(content: Content) -> some View { func body(content: Content) -> some View {
if #available(iOS 15.0, macOS 12.0, tvOS 15.0, *) { if #available(iOS 15.0, macOS 12.0, tvOS 15.0, *) {
content content
.background(.thinMaterial) .background(.thinMaterial)
} else { } else {
content content
#if os(tvOS)
.background(Color.background(scheme: colorScheme))
#else
.background(Color.background.opacity(0.95)) .background(Color.background.opacity(0.95))
#endif
} }
} }
} }

View File

@ -106,7 +106,9 @@ struct PlayerControlsView<Content: View>: View {
.background(Material.ultraThinMaterial) .background(Material.ultraThinMaterial)
} else { } else {
controls controls
#if !os(tvOS)
.background(Color.tertiaryBackground) .background(Color.tertiaryBackground)
#endif
} }
} }
} }