-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGenderView.swift
71 lines (67 loc) · 1.89 KB
/
GenderView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// GenderView.swift
// covid19-sounds
//
// Authors (by order of contribution):
//
// Andreas Grammenos
// Api Hastanasombat
//
// Copyright © 2020 Computer Lab / Mobile Systems Group. All rights reserved.
//
import SwiftUI
/// This `View` is responsible for showing the Gender selection choices for the user.
///
struct GenderView: View {
// the `InitialQuestionnaireInstance` instance as an `EnvironmentObject`.
@EnvironmentObject private var initialQuestionnaireInstance: InitialQuestionnaireInstance
// The sex state variable
@State private var sex_choice = 0
// the sex choices
private let sex_choices: [KeyValueTuple] = [
("Male", "maleTag"),
("Female", "femaleTag"),
("Other", "otherTag"),
("ptns", "Prefer not to say")
]
/// the body view definition
var body: some View {
VStack {
//
Spacer()
//
TextViewFactory("bioSex")
//
// that's the only way to get the label values
Picker(selection: $sex_choice, label: Text("sex")) {
ForEach(0 ..< sex_choices.count) {
Text(self.sex_choices[$0].value)
}
}
.padding(.top, -35.0)
.labelsHidden()
//
NavigationLinkFactory<AgeView>(nextView: AgeView())
.modifier(NavigationLinkModifier({
// conveniently wrap it
let selected_sex = self.sex_choices[self.sex_choice].key
// log it
log.info("Gender selected: \(selected_sex)")
// assign it to our instance structure
self.initialQuestionnaireInstance.sex = selected_sex
}))
//
Spacer()
}.modifier(AppBackgroundStyle())
}
}
// only render this in debug mode
#if DEBUG
struct GenderView_Previews: PreviewProvider {
static var previews: some View {
GenderView()
.environmentObject(debugInitialQuestionnaireInstance)
.environment(\.locale, .init(identifier: debugLocale))
}
}
#endif