|
1 | 1 | import SwiftUI |
2 | 2 |
|
3 | 3 | 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 { |
4 | 16 | @AppStorage(.storageKeys.colorScheme) |
5 | 17 | private var preference: ColorSchemePreference = .system |
6 | 18 |
|
7 | 19 | @AppStorage(.storageKeys.openFirstResult) |
8 | 20 | private var openFirstResult = false |
9 | 21 |
|
10 | | - @Environment(\.dismiss) private var dismiss |
11 | | - |
12 | 22 | 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) |
26 | 31 | } |
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) |
40 | 34 | } |
| 35 | + .pickerStyle(.navigationLink) |
| 36 | + } footer: { |
| 37 | + Text("Controls the app's theme preference.") |
| 38 | + } |
| 39 | + #endif |
41 | 40 |
|
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) |
54 | 50 | } |
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 | | - ) |
63 | 51 | } |
| 52 | + } footer: { |
| 53 | + Text("Controls the app's theme preference.") |
| 54 | + } |
64 | 55 |
|
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 | + ) |
68 | 65 | } |
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 | + ) |
71 | 85 | } |
| 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) |
72 | 95 | } |
73 | 96 | } |
74 | 97 | } |
75 | 98 |
|
76 | 99 | #if DEBUG |
77 | | -#Preview("View") { |
| 100 | +#Preview { |
78 | 101 | @Previewable @AppStorage(.storageKeys.colorScheme) |
79 | 102 | var preference: ColorSchemePreference = .system |
80 | 103 |
|
81 | | - SettingsSheet() |
82 | | - .preferredColorScheme(preference.colorScheme) |
83 | | -} |
| 104 | + @Previewable @Environment(\.colorScheme) var systemScheme |
84 | 105 |
|
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 |
90 | 107 |
|
91 | 108 | Button("Open settings") { |
92 | | - router.sheetItem = .settings |
| 109 | + isPresented = true |
| 110 | + } |
| 111 | + .sheet(isPresented: $isPresented) { |
| 112 | + SettingsSheet() |
| 113 | + .preferredColorScheme(preference.colorScheme ?? systemScheme) |
93 | 114 | } |
94 | 115 | .buttonStyle(.borderedProminent) |
95 | | - .withSheetDestination($router.sheetItem) |
96 | 116 | .preferredColorScheme(preference.colorScheme) |
97 | 117 | } |
98 | 118 | #endif |
0 commit comments