Skip to content

Commit 1406cf9

Browse files
author
Rick Pasetto
authored
LOOP-2325: iOS14: use InsetGroupedListStyle for iOS 14 (#338)
This adds a View modifier that will use InsetGroupedListStyle for iOS 14, but fall back to the old GroupedListStyle with horizontalSizeClass override hack for prior iOS versions.
1 parent 32863d4 commit 1406cf9

File tree

5 files changed

+11
-16
lines changed

5 files changed

+11
-16
lines changed

Loop/Views/BolusEntryView.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import LoopKitUI
1414
import LoopUI
1515

1616

17-
struct BolusEntryView: View, HorizontalSizeClassOverride {
17+
struct BolusEntryView: View {
1818
@ObservedObject var viewModel: BolusEntryViewModel
1919

2020
@State private var enteredBolusAmount = ""
@@ -40,8 +40,7 @@ struct BolusEntryView: View, HorizontalSizeClassOverride {
4040
// Unfortunately, after entry, the field scoots back down and remains hidden. So this is not a great solution.
4141
// TODO: Fix this in Xcode 12 when we're building for iOS 14.
4242
.padding(.top, self.shouldAutoScroll(basedOn: geometry) ? -200 : -28)
43-
.listStyle(GroupedListStyle())
44-
.environment(\.horizontalSizeClass, self.horizontalOverride)
43+
.insetGroupedListStyle()
4544

4645
self.actionArea
4746
.frame(height: self.isKeyboardVisible ? 0 : nil)

Loop/Views/NotificationsCriticalAlertPermissionsView.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import LoopKitUI
1010
import SwiftUI
1111

12-
public struct NotificationsCriticalAlertPermissionsView: View, HorizontalSizeClassOverride {
12+
public struct NotificationsCriticalAlertPermissionsView: View {
1313
@Environment(\.dismiss) private var dismiss
1414
@Environment(\.appName) private var appName
1515

@@ -49,10 +49,9 @@ public struct NotificationsCriticalAlertPermissionsView: View, HorizontalSizeCla
4949
manageCriticalAlertsSection
5050
notificationAndCriticalAlertPermissionSupportSection
5151
}
52-
.listStyle(GroupedListStyle())
52+
.insetGroupedListStyle()
5353
.navigationBarTitle(Text(NSLocalizedString("Alert Permissions", comment: "Notification & Critical Alert Permissions screen title")))
5454
.navigationBarItems(leading: dismissButton)
55-
.environment(\.horizontalSizeClass, horizontalOverride)
5655
}
5756
}
5857

Loop/Views/SettingsView.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import MockKit
1212
import SwiftUI
1313
import HealthKit
1414

15-
public struct SettingsView: View, HorizontalSizeClassOverride {
15+
public struct SettingsView: View {
1616
@Environment(\.dismiss) private var dismiss
1717
@Environment(\.appName) private var appName
1818
@Environment(\.carbTintColor) private var carbTintColor
@@ -52,10 +52,9 @@ public struct SettingsView: View, HorizontalSizeClassOverride {
5252
}
5353
supportSection
5454
}
55-
.listStyle(GroupedListStyle())
55+
.insetGroupedListStyle()
5656
.navigationBarTitle(Text(NSLocalizedString("Settings", comment: "Settings screen title")))
5757
.navigationBarItems(trailing: dismissButton)
58-
.environment(\.horizontalSizeClass, horizontalOverride)
5958
}
6059
}
6160

@@ -205,7 +204,7 @@ extension SettingsView {
205204
ForEach(viewModel.servicesViewModel.activeServices().indices, id: \.self) { index in
206205
LargeButton(action: { self.viewModel.servicesViewModel.didTapService(index) },
207206
includeArrow: true,
208-
imageView: self.serviceImage(uiImage: (self.viewModel.servicesViewModel.activeServices()[index] as! ServiceUI).image),
207+
imageView: self.serviceImage(uiImage: (self.viewModel.servicesViewModel.activeServices()[index] as? ServiceUI)?.image),
209208
label: self.viewModel.servicesViewModel.activeServices()[index].localizedTitle,
210209
descriptiveText: "")
211210
}

Loop/Views/SimpleBolusView.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import LoopKitUI
1212
import HealthKit
1313
import LoopCore
1414

15-
struct SimpleBolusView: View, HorizontalSizeClassOverride {
15+
struct SimpleBolusView: View {
1616

1717
@Environment(\.dismiss) var dismiss
1818

@@ -48,8 +48,7 @@ struct SimpleBolusView: View, HorizontalSizeClassOverride {
4848
// Unfortunately, after entry, the field scoots back down and remains hidden. So this is not a great solution.
4949
// TODO: Fix this in Xcode 12 when we're building for iOS 14.
5050
.padding(.top, self.shouldAutoScroll(basedOn: geometry) ? -200 : 0)
51-
.listStyle(GroupedListStyle()) // In iOS 14, this should be InsetGroupedListStyle()
52-
.environment(\.horizontalSizeClass, .regular)
51+
.insetGroupedListStyle()
5352
.navigationBarTitle(Text(self.title), displayMode: .inline)
5453

5554
self.actionArea

Loop/Views/SupportScreenView.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct SupportMenuItem: Identifiable {
1616
var menuItemView: AnyView
1717
}
1818

19-
struct SupportScreenView: View, HorizontalSizeClassOverride {
19+
struct SupportScreenView: View {
2020
@Environment(\.dismiss) private var dismiss
2121

2222
var didTapIssueReport: ((_ title: String) -> Void)?
@@ -44,9 +44,8 @@ struct SupportScreenView: View, HorizontalSizeClassOverride {
4444
}
4545
}
4646
}
47-
.listStyle(GroupedListStyle())
47+
.insetGroupedListStyle()
4848
.navigationBarTitle(Text("Support", comment: "Support screen title"))
49-
.environment(\.horizontalSizeClass, horizontalOverride)
5049
}
5150

5251
func openURL(_ url: URL) {

0 commit comments

Comments
 (0)