Skip to content

Commit 02e6ba0

Browse files
committed
fix(settings): make settings sheet follow color scheme.
1 parent b48652a commit 02e6ba0

9 files changed

Lines changed: 282 additions & 117 deletions

File tree

‎Snapper/Features/AlbumHistory/AlbumSelectableCard.swift‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,22 +170,19 @@ private struct TestSelectableGrid: View {
170170
}
171171
.withFullBackground()
172172
.task {
173-
let offsets: [(value: Int, unit: Calendar.Component)] = [
174-
(1, .minute),
175-
(1, .hour),
176-
(1, .day),
177-
(1, .weekOfYear),
178-
(1, .month),
179-
(1, .year),
173+
let offsets: [DateOffset] = [
174+
.minutes(1),
175+
.hours(1),
176+
.days(1),
177+
.weeks(1),
178+
.months(1),
179+
.years(1),
180180
]
181181

182182
guard albums.count >= offsets.count else { return }
183183

184184
for (album, offset) in albums.paired(with: offsets) {
185-
album.selectedAt = album.selectedAt.subtracting(
186-
offset.value,
187-
unit: offset.unit,
188-
)
185+
album.selectedAt = album.selectedAt.subtracting(offset)
189186
}
190187
}
191188
}

‎Snapper/Features/AlbumMap/AlbumClusterView.swift‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,18 @@ private struct TestAlbumClusterView: View {
102102
}
103103
}
104104
.task {
105-
let offsets: [(value: Int, unit: Calendar.Component)] = [
106-
(1, .hour),
107-
(1, .day),
108-
(2, .day),
109-
(1, .weekOfYear),
110-
(1, .month),
105+
let offsets: [DateOffset] = [
106+
.hours(1),
107+
.days(1),
108+
.days(2),
109+
.weeks(1),
110+
.months(1),
111111
]
112112

113113
guard albums.count >= offsets.count else { return }
114114

115115
for (album, offset) in albums.paired(with: offsets, stride: 2) {
116-
album.selectedAt = album.selectedAt.subtracting(
117-
offset.value,
118-
unit: offset.unit,
119-
)
116+
album.selectedAt = album.selectedAt.subtracting(offset)
120117
}
121118
}
122119
}

‎Snapper/Features/AlbumMap/AlbumMapView.swift‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,11 @@ private struct AlbumClusterSheet: View {
192192
}
193193
}
194194
.navigationBarTitleDisplayMode(.inline)
195-
.presentationDetents([.medium, .large])
195+
.presentationDetents([
196+
pin.albums.count <= 3
197+
? .medium
198+
: .large
199+
])
196200
.withCloseButton()
197201
}
198202
}

‎Snapper/Features/AlbumSearch/AlbumSearchView.swift‎

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ import SwiftData
22
import SwiftUI
33

44
struct HomeView: View {
5+
@AppStorage(.storageKeys.colorScheme)
6+
private var preference: ColorSchemePreference = .system
7+
58
@AppStorage(.storageKeys.openFirstResult)
69
private var openFirstResult = true
710

811
@Environment(\.locale) private var locale
12+
@Environment(\.colorScheme) private var systemScheme
913

1014
@Environment(AlbumSearchViewModel.self) private var vm
1115

@@ -82,24 +86,25 @@ struct HomeView: View {
8286
}
8387
}
8488
}
89+
.task(id: searchText) {
90+
await vm.search(by: .term(searchText), locale: locale)
91+
}
92+
.sheet(isPresented: $isSettingsPresented) {
93+
SettingsSheet()
94+
.preferredColorScheme(preference.colorScheme ?? systemScheme)
95+
.presentationDetents([
96+
.fraction(3 / 4)
97+
])
98+
}
99+
.sheet(item: $selectedAlbum) { album in
100+
AlbumCreation(album: album)
101+
.presentationDetents([
102+
.large
103+
])
104+
}
85105
.withFullBackground()
86106
.dismissKeyboardOnTap()
87107
}
88-
.task(id: searchText) {
89-
await vm.search(by: .term(searchText), locale: locale)
90-
}
91-
.sheet(isPresented: $isSettingsPresented) {
92-
SettingsSheet()
93-
.presentationDetents([
94-
.medium
95-
])
96-
}
97-
.sheet(item: $selectedAlbum) { album in
98-
AlbumCreation(album: album)
99-
.presentationDetents([
100-
.large
101-
])
102-
}
103108
}
104109

105110
private func onBarcode(_ barcode: String) {

‎Snapper/Features/Settings/SchemeSelectionView.swift‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,18 @@ struct SchemeSelectionView: View {
44
@Binding var selection: ColorSchemePreference
55

66
var body: some View {
7-
List {
8-
ForEach(ColorSchemePreference.allCases) { option in
9-
Button {
10-
selection = option
11-
} label: {
12-
HStack {
13-
Text(option.displayName)
14-
.frame(maxWidth: .infinity, alignment: .leading)
15-
16-
Image(systemName: "checkmark")
17-
.opacity(selection == option ? 1 : 0)
18-
.foregroundStyle(.accent)
19-
}
7+
List(ColorSchemePreference.allCases) { option in
8+
Button {
9+
selection = option
10+
} label: {
11+
LabeledContent(option.displayName) {
12+
Image(systemName: "checkmark")
13+
.opacity(selection == option ? 1 : 0)
14+
.foregroundStyle(.accent)
15+
.bold()
2016
}
21-
.buttonStyle(.plain)
2217
}
18+
.buttonStyle(.plain)
2319
}
2420
}
2521
}
Lines changed: 84 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,118 @@
11
import SwiftUI
22

33
struct SettingsSheet: View {
4+
var body: some View {
5+
NavigationStack {
6+
SettingsView()
7+
.navigationTitle("Settings")
8+
.navigationBarTitleDisplayMode(.inline)
9+
.presentationDetents([.medium, .large])
10+
.withCloseButton()
11+
}
12+
}
13+
}
14+
15+
private struct SettingsView: View {
416
@AppStorage(.storageKeys.colorScheme)
517
private var preference: ColorSchemePreference = .system
618

719
@AppStorage(.storageKeys.openFirstResult)
820
private var openFirstResult = false
921

10-
@Environment(\.dismiss) private var dismiss
11-
1222
var body: some View {
13-
NavigationStack {
14-
Form {
15-
Section {
16-
NavigationLink {
17-
SchemeSelectionView(selection: $preference)
18-
.navigationTitle("Theme")
19-
} label: {
20-
HStack {
21-
Text("Theme")
22-
.frame(maxWidth: .infinity, alignment: .leading)
23-
24-
Text(preference.displayName)
25-
}
23+
Form {
24+
#if false
25+
// When using the below, picking an item will immediately return to the nav. root.
26+
Section {
27+
Picker("Theme", selection: $preference) {
28+
ForEach(ColorSchemePreference.allCases) { option in
29+
Text(option.displayName)
30+
.tag(option)
2631
}
27-
} footer: {
28-
Text("Controls the app's theme preference.")
29-
}
30-
31-
Section {
32-
Toggle("Open first barcode result", isOn: $openFirstResult)
33-
} footer: {
34-
Text(
35-
"""
36-
Show album details directly after scanning a barcode. \
37-
You can review other results before adding.
38-
"""
39-
)
32+
.containerBackground(.clear, for: .navigation)
33+
.scrollContentBackground(.hidden)
4034
}
35+
.pickerStyle(.navigationLink)
36+
} footer: {
37+
Text("Controls the app's theme preference.")
38+
}
39+
#endif
4140

42-
Section {
43-
Button {
44-
if let url = URL(string: UIApplication.openSettingsURLString) {
45-
UIApplication.shared.open(url)
46-
}
47-
} label: {
48-
HStack {
49-
Text("Location")
50-
Spacer()
51-
Image(systemName: "chevron.right")
52-
.foregroundStyle(.secondary)
53-
}
41+
Section {
42+
NavigationLink {
43+
SchemeSelectionView(selection: $preference)
44+
.containerBackground(.clear, for: .navigation)
45+
.scrollContentBackground(.hidden)
46+
.navigationTitle("Theme")
47+
} label: {
48+
LabeledContent("Theme") {
49+
Text(preference.displayName)
5450
}
55-
.buttonStyle(.plain)
56-
} footer: {
57-
Text(
58-
"""
59-
Grant permission to access the device location in Settings, \
60-
to allow capturing the approximate location when adding an album.
61-
"""
62-
)
6351
}
52+
} footer: {
53+
Text("Controls the app's theme preference.")
54+
}
6455

65-
Text("Made for the ❤️ of 🎵 in 🇲🇽")
66-
.frame(maxWidth: .infinity, alignment: .trailing)
67-
.listRowBackground(Color.clear)
56+
Section {
57+
Toggle("Open first barcode result", isOn: $openFirstResult)
58+
} footer: {
59+
Text(
60+
"""
61+
Show album details directly after scanning a barcode. \
62+
You can review other results before adding.
63+
"""
64+
)
6865
}
69-
.navigationToolbar(title: "Settings") {
70-
dismiss()
66+
67+
Section {
68+
Button {
69+
if let url = URL(string: UIApplication.openSettingsURLString) {
70+
UIApplication.shared.open(url)
71+
}
72+
} label: {
73+
LabeledContent("Location") {
74+
Image(systemName: "chevron.right")
75+
}
76+
}
77+
.buttonStyle(.plain)
78+
} footer: {
79+
Text(
80+
"""
81+
Grant permission to access the device location in Settings, \
82+
to allow capturing the approximate location when adding an album.
83+
"""
84+
)
7185
}
86+
87+
Text("Made for the ❤️ of 🎵 in 🇲🇽")
88+
.frame(
89+
maxWidth: .infinity,
90+
maxHeight: .infinity,
91+
alignment: .center,
92+
)
93+
.listRowBackground(Color.clear)
94+
.font(.caption)
7295
}
7396
}
7497
}
7598

7699
#if DEBUG
77-
#Preview("View") {
100+
#Preview {
78101
@Previewable @AppStorage(.storageKeys.colorScheme)
79102
var preference: ColorSchemePreference = .system
80103

81-
SettingsSheet()
82-
.preferredColorScheme(preference.colorScheme)
83-
}
104+
@Previewable @Environment(\.colorScheme) var systemScheme
84105

85-
#Preview("Sheet") {
86-
@Previewable @AppStorage(.storageKeys.colorScheme)
87-
var preference: ColorSchemePreference = .system
88-
89-
@Previewable @State var router = Router()
106+
@Previewable @State var isPresented = true
90107

91108
Button("Open settings") {
92-
router.sheetItem = .settings
109+
isPresented = true
110+
}
111+
.sheet(isPresented: $isPresented) {
112+
SettingsSheet()
113+
.preferredColorScheme(preference.colorScheme ?? systemScheme)
93114
}
94115
.buttonStyle(.borderedProminent)
95-
.withSheetDestination($router.sheetItem)
96116
.preferredColorScheme(preference.colorScheme)
97117
}
98118
#endif

0 commit comments

Comments
 (0)