comparison GeoQuiz/SettingsModalView.swift @ 10:a793f33f05fb

refactor code and fix layout
author Dennis C. M. <dennis@denniscm.com>
date Sat, 08 Oct 2022 21:36:40 +0200
parents 3540c7efc216
children 136928bae534
comparison
equal deleted inserted replaced
9:3540c7efc216 10:a793f33f05fb
8 import SwiftUI 8 import SwiftUI
9 9
10 struct SettingsModalView: View { 10 struct SettingsModalView: View {
11 @Environment(\.dismiss) var dismiss 11 @Environment(\.dismiss) var dismiss
12 @StateObject var user = User() 12 @StateObject var user = User()
13
14 var lives: [Int] {
15 var lives = [Int]()
16 for i in stride(from: 5, to: 55, by: 5) {
17 lives.append(i)
18 }
19
20 return lives
21 }
13 22
14 var body: some View { 23 var body: some View {
15 NavigationView { 24 NavigationView {
16 Form { 25 Form {
17 Section { 26 Section {
18 Picker("Number of lives", selection: $user.settings.numberOfLives) { 27 Picker("❤️ Lives", selection: $user.settings.numberOfLives) {
19 ForEach(1..<11) { numberOfLives in 28 ForEach(lives, id: \.self) { numberOfLives in
20 Text("\(numberOfLives)") 29 Text("\(numberOfLives)")
21 .tag(numberOfLives) 30 .tag(numberOfLives)
22 } 31 }
23 } 32 }
24 } header: { 33 } header: {
25 Text("Game") 34 Text("Game")
35 } footer: {
36 Text("Number of lives at the beginning of each game.")
26 } 37 }
27 38
28 Section { 39 Section {
29 Toggle("Haptics", isOn: $user.settings.haptics) 40 Toggle("Haptics", isOn: $user.settings.haptics)
30 Toggle("Sound effects", isOn: $user.settings.sound) 41 Toggle("Sound effects", isOn: $user.settings.sound)