-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddNameView.swift
121 lines (107 loc) · 3.05 KB
/
AddNameView.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//
// AddNameView.swift
// Shoo
//
// Created by Benjamin Schiff on 5/31/20.
// Copyright © 2020 Alexander Schiff. All rights reserved.
//
import SwiftUI
struct AddNameView: View {
@EnvironmentObject var fire: Fire
@State private var name = ""
@Environment(\.presentationMode) var presentationMode
init() {
UINavigationBar.appearance().backgroundColor = UIColor.secondarySystemBackground
}
@State private var color: Color = Color.gray
@State private var isEditing = true
@State private var alert = false
var body: some View {
ZStack{
Color(UIColor.secondarySystemBackground)
.edgesIgnoringSafeArea(.all)
VStack(alignment: .leading){
HStack{
Text("Add name")
.font(.largeTitle)
.fontWeight(.bold)
Spacer()
Button(action: {
if !self.name.isEmpty {
UIApplication.shared.endEditing() // Call to dismiss keyboard
self.fire.changeName(self.name)
buttonPressHaptic(self.fire.reduceHaptics)
self.presentationMode.wrappedValue.dismiss()
} else{
self.color = Color.gray
self.alert = true
}
}){
Text("Next".uppercased())
.font(.headline)
.fontWeight(.semibold)
.foregroundColor(color)
}
.padding(8)
.background(Color(UIColor.systemBackground))
.clipShape(RoundedRectangle(cornerRadius: 30, style: .continuous))
}
.padding()
VStack(alignment: .leading){
Text("Please add your name")
.font(.headline)
ZStack{
TextField(name, text: $name, onEditingChanged: { _ in
self.color = Color.blue
}, onCommit: {
if !self.name.isEmpty {
self.fire.changeName(self.name)
self.presentationMode.wrappedValue.dismiss()
} else{
self.color = Color.gray
self.alert = true
}
})
.textFieldStyle(PlainTextFieldStyle())
.padding()
.background(Color(UIColor.systemBackground))
.clipShape(RoundedRectangle(cornerRadius: 20, style: .continuous))
HStack{
Spacer()
Button(action: {
if !self.name.isEmpty {
UIApplication.shared.endEditing() // Call to dismiss keyboard
self.fire.changeName(self.name)
buttonPressHaptic(self.fire.reduceHaptics)
self.presentationMode.wrappedValue.dismiss()
} else{
self.color = Color.gray
self.alert = true
}
}){
Image(systemName: "checkmark.circle")
.padding(.trailing)
.font(.title)
.foregroundColor(color)
}
}
}
Spacer()
}
.alert(isPresented: $alert){
Alert(title: Text("Enter name"), message: Text("Others need to know who you are! You can edit this name later."), dismissButton: .cancel(Text("OK")))
}
.padding()
.onAppear{
self.name = self.fire.profile.name
}
}
}
.highPriorityGesture(DragGesture())
}
}
struct AddNameView_Previews: PreviewProvider {
static var previews: some View {
AddNameView().environmentObject(Fire())
}
}