From 04ca932a01458c64c7827a8f68cb9ed9d4d7d237 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 6 Feb 2023 18:42:55 -0500 Subject: [PATCH] Mode non-pure-black dark mode stuff to dedicated modifiers --- Tusker.xcodeproj/project.pbxproj | 4 ++ Tusker/Extensions/View+AppListStyle.swift | 48 +++++++++++++++++++ Tusker/Screens/Compose/ComposeView.swift | 2 +- .../AddHashtagPinnedTimelineView.swift | 5 +- .../CustomizeTimelinesView.swift | 14 ++---- .../Customize Timelines/EditFilterView.swift | 25 +++------- Tusker/Screens/Mute/MuteAccountView.swift | 12 ++--- .../Screens/Preferences/About/AboutView.swift | 6 +-- .../Preferences/AcknowledgementsView.swift | 2 +- .../Preferences/AdvancedPrefsView.swift | 10 ++-- .../Preferences/AppearancePrefsView.swift | 8 ++-- .../Preferences/BehaviorPrefsView.swift | 10 ++-- .../Preferences/ComposingPrefsView.swift | 10 ++-- .../Screens/Preferences/MediaPrefsView.swift | 4 +- .../OppositeCollapseKeywordsView.swift | 8 ++-- .../Screens/Preferences/PreferencesView.swift | 27 ++--------- .../Preferences/WellnessPrefsView.swift | 12 ++--- .../Screens/Report/ReportAddStatusView.swift | 2 +- .../Report/ReportSelectRulesView.swift | 2 +- Tusker/Screens/Report/ReportView.swift | 26 ++++------ 20 files changed, 121 insertions(+), 116 deletions(-) create mode 100644 Tusker/Extensions/View+AppListStyle.swift diff --git a/Tusker.xcodeproj/project.pbxproj b/Tusker.xcodeproj/project.pbxproj index 3b947d25..c1f6f59a 100644 --- a/Tusker.xcodeproj/project.pbxproj +++ b/Tusker.xcodeproj/project.pbxproj @@ -299,6 +299,7 @@ D6C3F4F7298ED7F70009FCFF /* FavoritesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C3F4F6298ED7F70009FCFF /* FavoritesViewController.swift */; }; D6C3F4F9298EDBF20009FCFF /* ConversationTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C3F4F8298EDBF20009FCFF /* ConversationTree.swift */; }; D6C3F4FB299035650009FCFF /* TrendsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C3F4FA299035650009FCFF /* TrendsViewController.swift */; }; + D6C3F5172991C1A00009FCFF /* View+AppListStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C3F5162991C1A00009FCFF /* View+AppListStyle.swift */; }; D6C693EF216192C2007D6A6D /* TuskerNavigationDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C693EE216192C2007D6A6D /* TuskerNavigationDelegate.swift */; }; D6C693FC2162FE6F007D6A6D /* LoadingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C693FB2162FE6F007D6A6D /* LoadingViewController.swift */; }; D6C693FE2162FEEA007D6A6D /* UIViewController+Children.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C693FD2162FEEA007D6A6D /* UIViewController+Children.swift */; }; @@ -712,6 +713,7 @@ D6C3F4F6298ED7F70009FCFF /* FavoritesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoritesViewController.swift; sourceTree = ""; }; D6C3F4F8298EDBF20009FCFF /* ConversationTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationTree.swift; sourceTree = ""; }; D6C3F4FA299035650009FCFF /* TrendsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrendsViewController.swift; sourceTree = ""; }; + D6C3F5162991C1A00009FCFF /* View+AppListStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+AppListStyle.swift"; sourceTree = ""; }; D6C693EE216192C2007D6A6D /* TuskerNavigationDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TuskerNavigationDelegate.swift; sourceTree = ""; }; D6C693FB2162FE6F007D6A6D /* LoadingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingViewController.swift; sourceTree = ""; }; D6C693FD2162FEEA007D6A6D /* UIViewController+Children.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+Children.swift"; sourceTree = ""; }; @@ -1309,6 +1311,7 @@ D63CC70F2911F1E4000E19DE /* UIScrollView+Top.swift */, D61F758F29353B4300C0B37F /* FileManager+Size.swift */, D61F75AC293AF39000C0B37F /* Filter+Helpers.swift */, + D6C3F5162991C1A00009FCFF /* View+AppListStyle.swift */, ); path = Extensions; sourceTree = ""; @@ -2246,6 +2249,7 @@ D6E426B325337C7000C02E1C /* CustomEmojiImageView.swift in Sources */, D6D4DDD0212518A000E1C4BB /* AppDelegate.swift in Sources */, D61F75B3293BD89C00C0B37F /* UpdateFilterService.swift in Sources */, + D6C3F5172991C1A00009FCFF /* View+AppListStyle.swift in Sources */, D65B4B6A297777D900DABDFB /* StatusNotFoundView.swift in Sources */, D6412B0924B0291E00F5412E /* MyProfileViewController.swift in Sources */, D601FA5D297B2E6F00A8E8B5 /* ConversationCollectionViewController.swift in Sources */, diff --git a/Tusker/Extensions/View+AppListStyle.swift b/Tusker/Extensions/View+AppListStyle.swift new file mode 100644 index 00000000..6df35170 --- /dev/null +++ b/Tusker/Extensions/View+AppListStyle.swift @@ -0,0 +1,48 @@ +// +// View+AppListStyle.swift +// Tusker +// +// Created by Shadowfacts on 2/6/23. +// Copyright © 2023 Shadowfacts. All rights reserved. +// + +import SwiftUI +import Combine + +extension View { + @ViewBuilder + func appGroupedListBackground(container: UIAppearanceContainer.Type, applyBackground: Bool = true) -> some View { + if #available(iOS 16.0, *) { + if applyBackground { + self + .scrollContentBackground(.hidden) + .background(Color.appGroupedBackground.edgesIgnoringSafeArea(.all)) + } else { + self + .scrollContentBackground(.hidden) + } + } else { + self + .onAppear { + UITableView.appearance(whenContainedInInstancesOf: [container]).backgroundColor = .appGroupedBackground + } + } + } + + func appGroupedListRowBackground() -> some View { + self.modifier(AppGroupedListRowBackground()) + } +} + +private struct AppGroupedListRowBackground: ViewModifier { + @Environment(\.colorScheme) private var colorScheme + + func body(content: Content) -> some View { + if colorScheme == .dark, !Preferences.shared.pureBlackDarkMode { + content + .listRowBackground(Color.appGroupedCellBackground) + } else { + content + } + } +} diff --git a/Tusker/Screens/Compose/ComposeView.swift b/Tusker/Screens/Compose/ComposeView.swift index 2d869b70..5391786f 100644 --- a/Tusker/Screens/Compose/ComposeView.swift +++ b/Tusker/Screens/Compose/ComposeView.swift @@ -328,7 +328,7 @@ struct ComposeView: View { } } -private extension View { +extension View { @available(iOS, obsoleted: 16.0) @ViewBuilder func scrollDismissesKeyboardInteractivelyIfAvailable() -> some View { diff --git a/Tusker/Screens/Customize Timelines/AddHashtagPinnedTimelineView.swift b/Tusker/Screens/Customize Timelines/AddHashtagPinnedTimelineView.swift index 7bdad8ad..11156dc8 100644 --- a/Tusker/Screens/Customize Timelines/AddHashtagPinnedTimelineView.swift +++ b/Tusker/Screens/Customize Timelines/AddHashtagPinnedTimelineView.swift @@ -16,7 +16,6 @@ struct AddHashtagPinnedTimelineRepresentable: UIViewControllerRepresentable { @Binding var pinnedTimelines: [PinnedTimeline] func makeUIViewController(context: Context) -> UIHostingController { - UITableView.appearance(whenContainedInInstancesOf: [UIViewControllerType.self]).backgroundColor = .appGroupedBackground return UIHostingController(rootView: AddHashtagPinnedTimelineView(pinnedTimelines: $pinnedTimelines)) } @@ -49,6 +48,8 @@ struct AddHashtagPinnedTimelineView: View { var body: some View { NavigationView { list + .listStyle(.grouped) + .appGroupedListBackground(container: AddHashtagPinnedTimelineRepresentable.UIViewControllerType.self) .navigationTitle("Add Hashtag") .navigationBarTitleDisplayMode(.inline) .searchable(text: $viewModel.searchQuery, placement: .navigationBarDrawer(displayMode: .always), prompt: Text("Search for hashtags")) @@ -89,7 +90,7 @@ struct AddHashtagPinnedTimelineView: View { .listRowBackground(EmptyView()) .listRowSeparator(.hidden) } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } .listStyle(.grouped) diff --git a/Tusker/Screens/Customize Timelines/CustomizeTimelinesView.swift b/Tusker/Screens/Customize Timelines/CustomizeTimelinesView.swift index f18e5df3..703fdb05 100644 --- a/Tusker/Screens/Customize Timelines/CustomizeTimelinesView.swift +++ b/Tusker/Screens/Customize Timelines/CustomizeTimelinesView.swift @@ -31,15 +31,10 @@ struct CustomizeTimelinesList: View { if #available(iOS 16.0, *) { NavigationStack { navigationBody - .scrollContentBackground(.hidden) - .background(Color.appGroupedBackground) } } else { NavigationView { navigationBody - .onAppear { - UITableView.appearance(whenContainedInInstancesOf: [UIHostingController.self]).backgroundColor = .appGroupedBackground - } } .navigationViewStyle(.stack) } @@ -56,7 +51,7 @@ struct CustomizeTimelinesList: View { private var navigationBody: some View { List { PinnedTimelinesView(accountPreferences: mastodonController.accountPreferences) - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() Section { Toggle(isOn: $preferences.hideReblogsInTimelines) { @@ -68,7 +63,7 @@ struct CustomizeTimelinesList: View { } header: { Text("Home Timeline") } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() Section { filtersForEach(unexpiredFilters) @@ -82,7 +77,7 @@ struct CustomizeTimelinesList: View { } header: { Text("Active Filters") } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() if !expiredFilters.isEmpty { Section { @@ -90,10 +85,11 @@ struct CustomizeTimelinesList: View { } header: { Text("Expired Filters") } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } } .listStyle(.insetGrouped) + .appGroupedListBackground(container: UIHostingController.self) .navigationTitle(Text("Customize Timelines")) .navigationBarTitleDisplayMode(.inline) .toolbar { diff --git a/Tusker/Screens/Customize Timelines/EditFilterView.swift b/Tusker/Screens/Customize Timelines/EditFilterView.swift index 576ec9b9..12e3972f 100644 --- a/Tusker/Screens/Customize Timelines/EditFilterView.swift +++ b/Tusker/Screens/Customize Timelines/EditFilterView.swift @@ -72,7 +72,7 @@ struct EditFilterView: View { filter.title = newValue })) } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } Section { @@ -97,7 +97,7 @@ struct EditFilterView: View { } } } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() Section { if mastodonController.instanceFeatures.filtersV2 { @@ -122,7 +122,7 @@ struct EditFilterView: View { } } } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() Section { ForEach(FilterV1.Context.allCases, id: \.rawValue) { context in @@ -144,9 +144,10 @@ struct EditFilterView: View { } header: { Text("Contexts") } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } - .scrollContentBackgroundIfAvailable() + .appGroupedListBackground(container: UIHostingController.self) + .scrollDismissesKeyboardInteractivelyIfAvailable() .navigationTitle(create ? "Add Filter" : "Edit Filter") .navigationBarTitleDisplayMode(.inline) .toolbar { @@ -213,20 +214,6 @@ private struct FilterContextToggleStyle: ToggleStyle { } } -private extension View { - @available(iOS, obsoleted: 16.0) - @ViewBuilder - func scrollContentBackgroundIfAvailable() -> some View { - if #available(iOS 16.0, *) { - self - .scrollContentBackground(.hidden) - .background(Color.appGroupedBackground) - } else { - self - } - } -} - //struct EditFilterView_Previews: PreviewProvider { // static var previews: some View { // EditFilterView() diff --git a/Tusker/Screens/Mute/MuteAccountView.swift b/Tusker/Screens/Mute/MuteAccountView.swift index d91cf90a..af33fb12 100644 --- a/Tusker/Screens/Mute/MuteAccountView.swift +++ b/Tusker/Screens/Mute/MuteAccountView.swift @@ -43,15 +43,10 @@ struct MuteAccountView: View { if #available(iOS 16.0, *) { NavigationStack { navigationViewContent - .scrollContentBackground(.hidden) - .background(Color.appGroupedBackground) } } else { NavigationView { navigationViewContent - .onAppear { - UITableView.appearance(whenContainedInInstancesOf: [UIHostingController.self]).backgroundColor = .appGroupedBackground - } } .navigationViewStyle(.stack) } @@ -90,7 +85,7 @@ struct MuteAccountView: View { Text("This user's posts will be hidden from your timeline. You can still receive notifications from them.") } } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() Section { Picker(selection: $duration) { @@ -105,7 +100,7 @@ struct MuteAccountView: View { Text("The mute will automatically be removed after the selected time.") } } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() Button(action: self.mute) { if isMuting { @@ -120,8 +115,9 @@ struct MuteAccountView: View { } } .disabled(isMuting) - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } + .appGroupedListBackground(container: UIHostingController.self) .alertWithData("Erorr Muting", data: $error, actions: { error in Button("OK") {} }, message: { error in diff --git a/Tusker/Screens/Preferences/About/AboutView.swift b/Tusker/Screens/Preferences/About/AboutView.swift index b7e34ac5..f2b38f0b 100644 --- a/Tusker/Screens/Preferences/About/AboutView.swift +++ b/Tusker/Screens/Preferences/About/AboutView.swift @@ -42,7 +42,7 @@ struct AboutView: View { } } } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() Section { Link("Website", destination: URL(string: "https://vaccor.space/tusker")!) @@ -68,10 +68,10 @@ struct AboutView: View { Link("Source Code", destination: URL(string: "https://git.shadowfacts.net/shadowfacts/Tusker")!) Link("Issue Tracker", destination: URL(string: "https://git.shadowfacts.net/shadowfacts/Tusker/issues")!) } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } .listStyle(.insetGrouped) - .appGroupedScrollBackgroundIfAvailable() + .appGroupedListBackground(container: PreferencesNavigationController.self) .sheet(isPresented: $isShowingMailSheet) { MailSheet(logData: logData) } diff --git a/Tusker/Screens/Preferences/AcknowledgementsView.swift b/Tusker/Screens/Preferences/AcknowledgementsView.swift index 7eceb771..d38647e0 100644 --- a/Tusker/Screens/Preferences/AcknowledgementsView.swift +++ b/Tusker/Screens/Preferences/AcknowledgementsView.swift @@ -14,7 +14,7 @@ struct AcknowledgementsView: View { Text(text) .padding(.horizontal, 16) } - .appGroupedScrollBackgroundIfAvailable() + .appGroupedListBackground(container: PreferencesNavigationController.self) .navigationTitle("Acknowledgements") } diff --git a/Tusker/Screens/Preferences/AdvancedPrefsView.swift b/Tusker/Screens/Preferences/AdvancedPrefsView.swift index 6e0a2fe6..de53baba 100644 --- a/Tusker/Screens/Preferences/AdvancedPrefsView.swift +++ b/Tusker/Screens/Preferences/AdvancedPrefsView.swift @@ -24,7 +24,7 @@ struct AdvancedPrefsView : View { cachingSection } .listStyle(.insetGrouped) - .appGroupedScrollBackgroundIfAvailable() + .appGroupedListBackground(container: PreferencesNavigationController.self) .navigationBarTitle(Text("Advanced")) } @@ -51,7 +51,7 @@ struct AdvancedPrefsView : View { // see FB6838291 } } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } var cloudKitSection: some View { @@ -77,7 +77,7 @@ struct AdvancedPrefsView : View { } } } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() .task { CKContainer.default().accountStatus { status, error in if let error { @@ -103,7 +103,7 @@ struct AdvancedPrefsView : View { .lineLimit(nil) } } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } var cachingSection: some View { @@ -126,7 +126,7 @@ struct AdvancedPrefsView : View { } return Text(s) } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() .task { imageCacheSize = [ ImageCache.avatars, diff --git a/Tusker/Screens/Preferences/AppearancePrefsView.swift b/Tusker/Screens/Preferences/AppearancePrefsView.swift index 2fbd7a9f..d9f308d6 100644 --- a/Tusker/Screens/Preferences/AppearancePrefsView.swift +++ b/Tusker/Screens/Preferences/AppearancePrefsView.swift @@ -49,7 +49,7 @@ struct AppearancePrefsView : View { postsSection } .listStyle(.insetGrouped) - .appGroupedScrollBackgroundIfAvailable() + .appGroupedListBackground(container: PreferencesNavigationController.self) .navigationBarTitle(Text("Appearance")) } @@ -81,7 +81,7 @@ struct AppearancePrefsView : View { .onReceive(appearanceChangePublisher) { _ in NotificationCenter.default.post(name: .themePreferenceChanged, object: nil) } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } private var accountsSection: some View { @@ -93,7 +93,7 @@ struct AppearancePrefsView : View { Text("Hide Custom Emoji in Usernames") } } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } private var postsSection: some View { @@ -121,7 +121,7 @@ struct AppearancePrefsView : View { .navigationTitle("Trailing Swipe Actions") } } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } } diff --git a/Tusker/Screens/Preferences/BehaviorPrefsView.swift b/Tusker/Screens/Preferences/BehaviorPrefsView.swift index 6bc39932..71dafd47 100644 --- a/Tusker/Screens/Preferences/BehaviorPrefsView.swift +++ b/Tusker/Screens/Preferences/BehaviorPrefsView.swift @@ -19,7 +19,7 @@ struct BehaviorPrefsView: View { contentWarningsSection } .listStyle(.insetGrouped) - .appGroupedScrollBackgroundIfAvailable() + .appGroupedListBackground(container: PreferencesNavigationController.self) .navigationBarTitle(Text("Behavior")) } @@ -29,7 +29,7 @@ struct BehaviorPrefsView: View { Text("Require Confirmation Before Reblogging") } } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } private var timelineSection: some View { @@ -40,7 +40,7 @@ struct BehaviorPrefsView: View { } header: { Text("Timeline") } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } private var linksSection: some View { @@ -55,7 +55,7 @@ struct BehaviorPrefsView: View { Text("Always Use Reader Mode in In-App Safari") }.disabled(!preferences.useInAppSafari) } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } private var contentWarningsSection: some View { @@ -72,7 +72,7 @@ struct BehaviorPrefsView: View { Text(preferences.expandAllContentWarnings ? "Collapse Posts with Keywords in CWs" : "Expand Posts with Keywords in CWs") } } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } } diff --git a/Tusker/Screens/Preferences/ComposingPrefsView.swift b/Tusker/Screens/Preferences/ComposingPrefsView.swift index dc07e984..d1e91fda 100644 --- a/Tusker/Screens/Preferences/ComposingPrefsView.swift +++ b/Tusker/Screens/Preferences/ComposingPrefsView.swift @@ -20,7 +20,7 @@ struct ComposingPrefsView: View { writingSection } .listStyle(.insetGrouped) - .appGroupedScrollBackgroundIfAvailable() + .appGroupedListBackground(container: PreferencesNavigationController.self) .navigationBarTitle("Composing") } @@ -52,7 +52,7 @@ struct ComposingPrefsView: View { } footer: { Text("When starting a reply, Tusker will use your preferred visibility or the visibility of the post to which you're replying, whichever is narrower.") } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } var composingSection: some View { @@ -64,7 +64,7 @@ struct ComposingPrefsView: View { Text("Require Attachment Descriptions") } } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } var replyingSection: some View { @@ -78,7 +78,7 @@ struct ComposingPrefsView: View { Text("Mention Reblogger") } } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } var writingSection: some View { @@ -87,7 +87,7 @@ struct ComposingPrefsView: View { Text("Show @ and # on Keyboard") } } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } } diff --git a/Tusker/Screens/Preferences/MediaPrefsView.swift b/Tusker/Screens/Preferences/MediaPrefsView.swift index d358b52b..5dfbb51a 100644 --- a/Tusker/Screens/Preferences/MediaPrefsView.swift +++ b/Tusker/Screens/Preferences/MediaPrefsView.swift @@ -16,7 +16,7 @@ struct MediaPrefsView: View { viewingSection } .listStyle(.insetGrouped) - .appGroupedScrollBackgroundIfAvailable() + .appGroupedListBackground(container: PreferencesNavigationController.self) .navigationBarTitle("Media") } @@ -43,7 +43,7 @@ struct MediaPrefsView: View { Text("Show Uncropped Media Inline") } } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } } diff --git a/Tusker/Screens/Preferences/OppositeCollapseKeywordsView.swift b/Tusker/Screens/Preferences/OppositeCollapseKeywordsView.swift index 1930d86a..33443389 100644 --- a/Tusker/Screens/Preferences/OppositeCollapseKeywordsView.swift +++ b/Tusker/Screens/Preferences/OppositeCollapseKeywordsView.swift @@ -23,8 +23,8 @@ struct OppositeCollapseKeywordsView: View { ZStack { // the background from the grouped ListStyle clips to the safe area, so when the keyboard is hiding/showing // the color behind it can be seen, which looks odd - Color(UIColor.secondarySystemBackground) - .edgesIgnoringSafeArea(.bottom) +// Color(UIColor.secondarySystemBackground) +// .edgesIgnoringSafeArea(.bottom) List { Section(footer: Text("A post matches if its content warning contains the text of a keyword, ignoring case.")) { @@ -37,11 +37,11 @@ struct OppositeCollapseKeywordsView: View { FocusableTextField(placeholder: "Add Keyword", text: $valueToAdd, becomeFirstResponder: $makeAddFieldFirstResponder, onCommit: self.addKeyword) } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } .animation(.default, value: keywords.map(\.id)) .listStyle(.grouped) - .appGroupedScrollBackgroundIfAvailable() + .appGroupedListBackground(container: PreferencesNavigationController.self) } .onAppear(perform: updateAppearance) .navigationBarTitle(preferences.expandAllContentWarnings ? "Collapse Post CW Keywords" : "Expand Post CW Keywords") diff --git a/Tusker/Screens/Preferences/PreferencesView.swift b/Tusker/Screens/Preferences/PreferencesView.swift index e1e05c35..049002e8 100644 --- a/Tusker/Screens/Preferences/PreferencesView.swift +++ b/Tusker/Screens/Preferences/PreferencesView.swift @@ -24,14 +24,9 @@ struct PreferencesView: View { aboutSection } .listStyle(.insetGrouped) - .appGroupedScrollBackgroundIfAvailable() + .appGroupedListBackground(container: PreferencesNavigationController.self) .navigationBarTitle("Preferences") .navigationBarTitleDisplayMode(.inline) - .onAppear { - if #unavailable(iOS 16.0) { - UITableView.appearance(whenContainedInInstancesOf: [PreferencesNavigationController.self]).backgroundColor = .appGroupedBackground - } - } } private var accountsSection: some View { @@ -90,7 +85,7 @@ struct PreferencesView: View { } header: { Text("Accounts") } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } private var preferencesSection: some View { @@ -114,7 +109,7 @@ struct PreferencesView: View { Text("Advanced") } } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } private var aboutSection: some View { @@ -129,7 +124,7 @@ struct PreferencesView: View { AcknowledgementsView() } } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } func logoutPressed() { @@ -137,20 +132,6 @@ struct PreferencesView: View { } } -extension View { - @available(iOS, obsoleted: 16.0) - @ViewBuilder - func appGroupedScrollBackgroundIfAvailable() -> some View { - if #available(iOS 16.0, *) { - self - .scrollContentBackground(.hidden) - .background(Color.appGroupedBackground) - } else { - self - } - } -} - //#if DEBUG //struct PreferencesView_Previews : PreviewProvider { // static var previews: some View { diff --git a/Tusker/Screens/Preferences/WellnessPrefsView.swift b/Tusker/Screens/Preferences/WellnessPrefsView.swift index 03f97f00..97879a49 100644 --- a/Tusker/Screens/Preferences/WellnessPrefsView.swift +++ b/Tusker/Screens/Preferences/WellnessPrefsView.swift @@ -20,7 +20,7 @@ struct WellnessPrefsView: View { hideTrends } .listStyle(.insetGrouped) - .appGroupedScrollBackgroundIfAvailable() + .appGroupedListBackground(container: PreferencesNavigationController.self) .navigationBarTitle(Text("Digital Wellness")) } @@ -30,7 +30,7 @@ struct WellnessPrefsView: View { Text("Favorite and Reblog Counts in Conversations") } } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } private var notificationsMode: some View { @@ -41,7 +41,7 @@ struct WellnessPrefsView: View { } } } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } private var grayscaleImages: some View { @@ -50,7 +50,7 @@ struct WellnessPrefsView: View { Text("Grayscale Images") } } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } private var disableInfiniteScrolling: some View { @@ -59,7 +59,7 @@ struct WellnessPrefsView: View { Text("Disable Infinite Scrolling") } } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } private var hideTrends: some View { @@ -68,7 +68,7 @@ struct WellnessPrefsView: View { Text("Hide Trends") } } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } } diff --git a/Tusker/Screens/Report/ReportAddStatusView.swift b/Tusker/Screens/Report/ReportAddStatusView.swift index 275363ba..f2a6d372 100644 --- a/Tusker/Screens/Report/ReportAddStatusView.swift +++ b/Tusker/Screens/Report/ReportAddStatusView.swift @@ -34,7 +34,7 @@ struct ReportAddStatusView: View { ReportStatusView(status: status, mastodonController: mastodonController) } } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } .modifier(ScrollBackgroundModifier()) } else { diff --git a/Tusker/Screens/Report/ReportSelectRulesView.swift b/Tusker/Screens/Report/ReportSelectRulesView.swift index f542cbef..703695e5 100644 --- a/Tusker/Screens/Report/ReportSelectRulesView.swift +++ b/Tusker/Screens/Report/ReportSelectRulesView.swift @@ -47,7 +47,7 @@ struct ReportSelectRulesView: View { .foregroundColor(selectedRuleIDs.contains(rule.id) ? .accentColor : .clear) } } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } .withAppBackgroundIfAvailable() .navigationTitle("Rules") diff --git a/Tusker/Screens/Report/ReportView.swift b/Tusker/Screens/Report/ReportView.swift index cc4353f3..afe8f5dd 100644 --- a/Tusker/Screens/Report/ReportView.swift +++ b/Tusker/Screens/Report/ReportView.swift @@ -31,22 +31,12 @@ struct ReportView: View { var body: some View { if #available(iOS 16.0, *) { NavigationStack { - ZStack { - // .background doesn't work because it somehow changes color when the keyboard appears - Color.appGroupedBackground - .edgesIgnoringSafeArea(.all) - - navigationViewContent - .scrollContentBackground(.hidden) - .scrollDismissesKeyboard(.interactively) - } + navigationViewContent + .scrollDismissesKeyboard(.interactively) } } else { NavigationView { navigationViewContent - .onAppear { - UITableView.appearance(whenContainedInInstancesOf: [UIHostingController.self]).backgroundColor = .appGroupedBackground - } } .navigationViewStyle(.stack) } @@ -104,14 +94,14 @@ struct ReportView: View { } header: { Text("Reason") } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() Section { ComposeTextView(text: $report.comment, placeholder: Text("Add any additional comments")) .backgroundColor(.clear) .listRowInsets(EdgeInsets(top: 8, leading: 8, bottom: 8, trailing: 8)) } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() Section { ForEach(report.statusIDs, id: \.self) { id in @@ -129,14 +119,14 @@ struct ReportView: View { } footer: { Text("Attach posts to your report to provide additional context for moderators.") } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() Section { Toggle("Forward", isOn: $report.forward) } footer: { Text("You can choose to anonymously forward your report to the moderators of **\(account.url.host!)**.") } - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() Button(action: self.sendReport) { if isReporting { @@ -149,8 +139,10 @@ struct ReportView: View { } } .disabled(isReporting) - .listRowBackground(Color.appGroupedCellBackground) + .appGroupedListRowBackground() } + .listStyle(.insetGrouped) + .appGroupedListBackground(container: UIHostingController.self, applyBackground: true) .alertWithData("Error Reporting", data: $error, actions: { error in Button("OK") {} }, message: { error in