From 941e6a909d3a05a3a951bc97152df22c555cd05d Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sun, 5 Dec 2021 18:09:25 +0100 Subject: [PATCH] Set full screen views background color based on color scheme on tvOS (fixes #30) --- Extensions/Color+Background.swift | 6 +++--- Shared/Playlists/AddToPlaylistView.swift | 3 ++- Shared/Playlists/PlaylistFormView.swift | 3 ++- Shared/Settings/AccountForm.swift | 3 ++- Shared/Settings/InstanceForm.swift | 3 ++- Shared/Settings/SettingsView.swift | 4 +++- Shared/Views/ChannelPlaylistView.swift | 4 +++- Shared/Views/ChannelVideosView.swift | 6 ++++-- Shared/Views/DetailBadge.swift | 8 +++++++- Shared/Views/PlayerControlsView.swift | 4 +++- 10 files changed, 31 insertions(+), 13 deletions(-) diff --git a/Extensions/Color+Background.swift b/Extensions/Color+Background.swift index e02ea81d..d996fdd3 100644 --- a/Extensions/Color+Background.swift +++ b/Extensions/Color+Background.swift @@ -10,8 +10,8 @@ extension Color { static let secondaryBackground = Color(UIColor.secondarySystemBackground) static let tertiaryBackground = Color(UIColor.tertiarySystemBackground) #else - static let background = Color.black - static let secondaryBackground = Color.black - static let tertiaryBackground = Color.black + static func background(scheme: ColorScheme) -> Color { + scheme == .dark ? .black : .init(white: 0.8) + } #endif } diff --git a/Shared/Playlists/AddToPlaylistView.swift b/Shared/Playlists/AddToPlaylistView.swift index d557ef58..60bee678 100644 --- a/Shared/Playlists/AddToPlaylistView.swift +++ b/Shared/Playlists/AddToPlaylistView.swift @@ -7,6 +7,7 @@ struct AddToPlaylistView: View { @State private var selectedPlaylistID: Playlist.ID = "" + @Environment(\.colorScheme) private var colorScheme @Environment(\.presentationMode) private var presentationMode @EnvironmentObject private var model @@ -37,7 +38,7 @@ struct AddToPlaylistView: View { .padding(.vertical) #elseif os(tvOS) .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity) - .background(Color.tertiaryBackground) + .background(Color.background(scheme: colorScheme)) #else .padding(.vertical) #endif diff --git a/Shared/Playlists/PlaylistFormView.swift b/Shared/Playlists/PlaylistFormView.swift index 6c628dd8..4e196667 100644 --- a/Shared/Playlists/PlaylistFormView.swift +++ b/Shared/Playlists/PlaylistFormView.swift @@ -10,6 +10,7 @@ struct PlaylistFormView: View { @State private var valid = false @State private var showingDeleteConfirmation = false + @Environment(\.colorScheme) private var colorScheme @Environment(\.presentationMode) private var presentationMode @EnvironmentObject private var accounts @@ -77,7 +78,7 @@ struct PlaylistFormView: View { .frame(maxWidth: 1000) } .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity) - .background(Color.tertiaryBackground) + .background(Color.background(scheme: colorScheme)) #endif } .onChange(of: name) { _ in validate() } diff --git a/Shared/Settings/AccountForm.swift b/Shared/Settings/AccountForm.swift index e0d4b1fa..6b0dca3a 100644 --- a/Shared/Settings/AccountForm.swift +++ b/Shared/Settings/AccountForm.swift @@ -15,6 +15,7 @@ struct AccountForm: View { @State private var validationError: String? @State private var validationDebounce = Debounce() + @Environment(\.colorScheme) private var colorScheme @Environment(\.presentationMode) private var presentationMode var body: some View { @@ -30,7 +31,7 @@ struct AccountForm: View { .padding(.vertical) #elseif os(tvOS) .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity) - .background(Color.tertiaryBackground) + .background(Color.background(scheme: colorScheme)) #else .frame(width: 400, height: 145) #endif diff --git a/Shared/Settings/InstanceForm.swift b/Shared/Settings/InstanceForm.swift index e410681a..c7723e71 100644 --- a/Shared/Settings/InstanceForm.swift +++ b/Shared/Settings/InstanceForm.swift @@ -13,6 +13,7 @@ struct InstanceForm: View { @State private var validationError: String? @State private var validationDebounce = Debounce() + @Environment(\.colorScheme) private var colorScheme @Environment(\.presentationMode) private var presentationMode var body: some View { @@ -32,7 +33,7 @@ struct InstanceForm: View { .padding(.vertical) #elseif os(tvOS) .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity) - .background(Color.tertiaryBackground) + .background(Color.background(scheme: colorScheme)) #else .frame(width: 400, height: 190) #endif diff --git a/Shared/Settings/SettingsView.swift b/Shared/Settings/SettingsView.swift index 5d78d140..0b1b999a 100644 --- a/Shared/Settings/SettingsView.swift +++ b/Shared/Settings/SettingsView.swift @@ -9,6 +9,8 @@ struct SettingsView: View { } #endif + @Environment(\.colorScheme) private var colorScheme + #if os(iOS) @Environment(\.presentationMode) private var presentationMode #endif @@ -102,7 +104,7 @@ struct SettingsView: View { InstanceForm(savedInstanceID: $savedFormInstanceID) } #if os(tvOS) - .background(Color.black) + .background(Color.background(scheme: colorScheme)) #endif #endif } diff --git a/Shared/Views/ChannelPlaylistView.swift b/Shared/Views/ChannelPlaylistView.swift index fc16d5c5..f19c6ff0 100644 --- a/Shared/Views/ChannelPlaylistView.swift +++ b/Shared/Views/ChannelPlaylistView.swift @@ -9,6 +9,8 @@ struct ChannelPlaylistView: View { @StateObject private var store = Store() + @Environment(\.colorScheme) private var colorScheme + #if os(iOS) @Environment(\.inNavigationView) private var inNavigationView #endif @@ -83,7 +85,7 @@ struct ChannelPlaylistView: View { .navigationTitle(playlist.title) #else - .background(Color.tertiaryBackground) + .background(Color.background(scheme: colorScheme)) #endif } diff --git a/Shared/Views/ChannelVideosView.swift b/Shared/Views/ChannelVideosView.swift index efaa09e9..40d14dde 100644 --- a/Shared/Views/ChannelVideosView.swift +++ b/Shared/Views/ChannelVideosView.swift @@ -9,6 +9,7 @@ struct ChannelVideosView: View { @StateObject private var store = Store() + @Environment(\.colorScheme) private var colorScheme @Environment(\.presentationMode) private var presentationMode @Environment(\.inNavigationView) private var inNavigationView @@ -105,8 +106,6 @@ struct ChannelVideosView: View { } } } - #else - .background(Color.tertiaryBackground) #endif #if os(iOS) .sheet(isPresented: $presentingShareSheet) { @@ -126,6 +125,9 @@ struct ChannelVideosView: View { return Group { if #available(macOS 12.0, *) { content + #if os(tvOS) + .background(Color.background(scheme: colorScheme)) + #endif #if !os(iOS) .focusScope(focusNamespace) #endif diff --git a/Shared/Views/DetailBadge.swift b/Shared/Views/DetailBadge.swift index c527dc2f..956ef206 100644 --- a/Shared/Views/DetailBadge.swift +++ b/Shared/Views/DetailBadge.swift @@ -25,13 +25,19 @@ struct DetailBadge: View { } struct DefaultStyleModifier: ViewModifier { + @Environment(\.colorScheme) private var colorScheme + func body(content: Content) -> some View { if #available(iOS 15.0, macOS 12.0, tvOS 15.0, *) { content .background(.thinMaterial) } else { content - .background(Color.background.opacity(0.95)) + #if os(tvOS) + .background(Color.background(scheme: colorScheme)) + #else + .background(Color.background.opacity(0.95)) + #endif } } } diff --git a/Shared/Views/PlayerControlsView.swift b/Shared/Views/PlayerControlsView.swift index 0a9cf0c4..ae9230c4 100644 --- a/Shared/Views/PlayerControlsView.swift +++ b/Shared/Views/PlayerControlsView.swift @@ -106,7 +106,9 @@ struct PlayerControlsView: View { .background(Material.ultraThinMaterial) } else { controls - .background(Color.tertiaryBackground) + #if !os(tvOS) + .background(Color.tertiaryBackground) + #endif } } }