From 02135aa0de2bc1b56592e17929695f8f1852750c Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 15 Sep 2020 20:46:49 -0400 Subject: [PATCH] Use inset list style for preferences on iOS 14 --- .../Screens/Preferences/AdvancedPrefsView.swift | 7 ++++--- .../Preferences/AppearancePrefsView.swift | 4 ++-- .../Screens/Preferences/BehaviorPrefsView.swift | 4 +++- .../Preferences/ComposingPrefsView.swift | 4 +++- Tusker/Screens/Preferences/MediaPrefsView.swift | 4 +++- .../Screens/Preferences/PreferencesView.swift | 17 ++++++++++++++--- .../Screens/Preferences/SilentActionPrefs.swift | 2 +- .../Screens/Preferences/WellnessPrefsView.swift | 5 +++-- 8 files changed, 33 insertions(+), 14 deletions(-) diff --git a/Tusker/Screens/Preferences/AdvancedPrefsView.swift b/Tusker/Screens/Preferences/AdvancedPrefsView.swift index 78cd39f3..15190e7c 100644 --- a/Tusker/Screens/Preferences/AdvancedPrefsView.swift +++ b/Tusker/Screens/Preferences/AdvancedPrefsView.swift @@ -16,8 +16,9 @@ struct AdvancedPrefsView : View { formattingSection automationSection cachingSection - }.listStyle(GroupedListStyle()) - .navigationBarTitle(Text("Advanced")) + } + .insetOrGroupedListStyle() + .navigationBarTitle(Text("Advanced")) } var formattingFooter: some View { @@ -44,7 +45,7 @@ struct AdvancedPrefsView : View { } var cachingSection: some View { - Section(header: Text("Caching")) { + Section(header: Text("Caching"), footer: Text("Clearing caches will restart the app.")) { Button(action: clearCache) { Text("Clear Mastodon Cache") }.foregroundColor(.red) diff --git a/Tusker/Screens/Preferences/AppearancePrefsView.swift b/Tusker/Screens/Preferences/AppearancePrefsView.swift index d00195f9..1d9d3e7d 100644 --- a/Tusker/Screens/Preferences/AppearancePrefsView.swift +++ b/Tusker/Screens/Preferences/AppearancePrefsView.swift @@ -33,8 +33,8 @@ struct AppearancePrefsView : View { accountsSection postsSection } - .listStyle(GroupedListStyle()) - .navigationBarTitle(Text("Appearance")) + .insetOrGroupedListStyle() + .navigationBarTitle(Text("Appearance")) } private var accountsSection: some View { diff --git a/Tusker/Screens/Preferences/BehaviorPrefsView.swift b/Tusker/Screens/Preferences/BehaviorPrefsView.swift index a2f378c8..5eb85331 100644 --- a/Tusker/Screens/Preferences/BehaviorPrefsView.swift +++ b/Tusker/Screens/Preferences/BehaviorPrefsView.swift @@ -14,7 +14,9 @@ struct BehaviorPrefsView: View { var body: some View { List { linksSection - }.listStyle(GroupedListStyle()).navigationBarTitle(Text("Behavior")) + } + .insetOrGroupedListStyle() + .navigationBarTitle(Text("Behavior")) } var linksSection: some View { diff --git a/Tusker/Screens/Preferences/ComposingPrefsView.swift b/Tusker/Screens/Preferences/ComposingPrefsView.swift index 626fbea1..3eb20dfb 100644 --- a/Tusker/Screens/Preferences/ComposingPrefsView.swift +++ b/Tusker/Screens/Preferences/ComposingPrefsView.swift @@ -16,7 +16,9 @@ struct ComposingPrefsView: View { List { composingSection replyingSection - }.listStyle(GroupedListStyle()).navigationBarTitle("Composing") + } + .insetOrGroupedListStyle() + .navigationBarTitle("Composing") } var composingSection: some View { diff --git a/Tusker/Screens/Preferences/MediaPrefsView.swift b/Tusker/Screens/Preferences/MediaPrefsView.swift index ef8bf716..e644dc36 100644 --- a/Tusker/Screens/Preferences/MediaPrefsView.swift +++ b/Tusker/Screens/Preferences/MediaPrefsView.swift @@ -14,7 +14,9 @@ struct MediaPrefsView: View { var body: some View { List { viewingSection - }.listStyle(GroupedListStyle()).navigationBarTitle("Media") + } + .insetOrGroupedListStyle() + .navigationBarTitle("Media") } var viewingSection: some View { diff --git a/Tusker/Screens/Preferences/PreferencesView.swift b/Tusker/Screens/Preferences/PreferencesView.swift index e9b53f0b..65e54cff 100644 --- a/Tusker/Screens/Preferences/PreferencesView.swift +++ b/Tusker/Screens/Preferences/PreferencesView.swift @@ -15,7 +15,7 @@ struct PreferencesView: View { // workaround: the navigation view is provided by MyProfileTableViewController so that it can inject the Done button // NavigationView { List { - Section { + Section(header: Text("Accounts")) { ForEach(localData.accounts, id: \.accessToken) { (account) in Button(action: { NotificationCenter.default.post(name: .activateAccount, object: nil, userInfo: ["account": account]) @@ -75,8 +75,8 @@ struct PreferencesView: View { } } } - .listStyle(GroupedListStyle()) - .navigationBarTitle(Text("Preferences"), displayMode: .inline) + .insetOrGroupedListStyle() + .navigationBarTitle(Text("Preferences"), displayMode: .inline) // } } @@ -85,6 +85,17 @@ struct PreferencesView: View { } } +extension View { + @ViewBuilder + func insetOrGroupedListStyle() -> some View { + if #available(iOS 14.0, *) { + self.listStyle(InsetGroupedListStyle()) + } else { + self.listStyle(GroupedListStyle()) + } + } +} + #if DEBUG struct PreferencesView_Previews : PreviewProvider { static var previews: some View { diff --git a/Tusker/Screens/Preferences/SilentActionPrefs.swift b/Tusker/Screens/Preferences/SilentActionPrefs.swift index dae1fff7..a49b0edf 100644 --- a/Tusker/Screens/Preferences/SilentActionPrefs.swift +++ b/Tusker/Screens/Preferences/SilentActionPrefs.swift @@ -14,7 +14,7 @@ struct SilentActionPrefs : View { List(Array(preferences.silentActions.keys), id: \.self) { source in SilentActionPermissionCell(source: source) } - .listStyle(GroupedListStyle()) + .insetOrGroupedListStyle() // .navigationBarTitle("Silent Action Permissions") // see FB6838291 } diff --git a/Tusker/Screens/Preferences/WellnessPrefsView.swift b/Tusker/Screens/Preferences/WellnessPrefsView.swift index 72eca695..393c34a0 100644 --- a/Tusker/Screens/Preferences/WellnessPrefsView.swift +++ b/Tusker/Screens/Preferences/WellnessPrefsView.swift @@ -15,8 +15,9 @@ struct WellnessPrefsView: View { List { showFavAndReblogCountSection notificationsModeSection - }.listStyle(GroupedListStyle()) - .navigationBarTitle(Text("Digital Wellness")) + } + .insetOrGroupedListStyle() + .navigationBarTitle(Text("Digital Wellness")) } var showFavAndReblogCountSection: some View {