@@ -23,7 +23,32 @@ struct ContentView: View {
23
23
24
24
var body : some View {
25
25
NavigationView {
26
- List {
26
+ // Outer stack containing the list and the buttons.
27
+ VStack {
28
+ List {
29
+ VStack ( alignment: . leading) {
30
+ Text ( " InstanceID " ) . font ( . subheadline)
31
+ Text ( identity. instanceID ?? " None " ) . foregroundColor ( . blue)
32
+ }
33
+
34
+ VStack ( alignment: . leading) {
35
+ Text ( " Token " ) . font ( . subheadline)
36
+ Text ( identity. token ?? " None " )
37
+ . foregroundColor ( . blue)
38
+ // Increase the layout priority to allow more than one line to be shown. Without this, the
39
+ // simulator renders a single truncated line even though the Preview renders it
40
+ // appropriately. Potentially a bug in the simulator?
41
+ . layoutPriority ( 1 )
42
+ }
43
+
44
+ NavigationLink ( destination: DetailView ( ) ) {
45
+ Text ( " Show Detail View " )
46
+ }
47
+ }
48
+ . navigationBarTitle ( " Firebase Messaging " )
49
+
50
+ // MARK: Action buttons
51
+
27
52
Button ( action: getToken) {
28
53
HStack {
29
54
Image ( systemName: " arrow.clockwise.circle.fill " ) . font ( . body)
@@ -59,14 +84,6 @@ struct ContentView: View {
59
84
}
60
85
}
61
86
. buttonStyle ( IdentityButtonStyle ( ) )
62
-
63
- Text ( " InstanceID: \( identity. instanceID) " )
64
- . foregroundColor ( . blue)
65
- Text ( " Token: \( identity. token) " )
66
- . foregroundColor ( . blue)
67
- NavigationLink ( destination: DetailView ( ) ) {
68
- Text ( " Show Detail View " )
69
- }
70
87
}
71
88
}
72
89
}
@@ -92,7 +109,7 @@ struct ContentView: View {
92
109
print ( " Failed delete token: " , error)
93
110
return
94
111
}
95
- self . identity. token = " "
112
+ self . identity. token = nil
96
113
}
97
114
}
98
115
@@ -102,8 +119,8 @@ struct ContentView: View {
102
119
print ( " Failed delete ID: " , error)
103
120
return
104
121
}
105
- self . identity. instanceID = " "
106
- self . identity. token = " "
122
+ self . identity. instanceID = nil
123
+ self . identity. token = nil
107
124
}
108
125
}
109
126
@@ -113,7 +130,7 @@ struct ContentView: View {
113
130
print ( " Failed delete FID: " , error)
114
131
return
115
132
}
116
- self . identity. instanceID = " "
133
+ self . identity. instanceID = nil
117
134
}
118
135
}
119
136
}
@@ -123,15 +140,32 @@ struct DetailView: View {
123
140
124
141
var body : some View {
125
142
VStack {
126
- Text ( " InstanceID: \( self . identity. instanceID) " )
127
- Text ( " Token: \( self . identity. token) " )
143
+ Text ( " InstanceID: \( self . identity. instanceID ?? " None " ) " )
144
+ Text ( " Token: \( self . identity. token ?? " None " ) " )
128
145
}
129
146
}
130
147
}
131
148
132
149
struct ContentView_Previews : PreviewProvider {
150
+ // A fake filled identity for testing rendering of a filled cell.
151
+ static let filledIdentity : Identity = {
152
+ var identity = Identity ( )
153
+ identity. instanceID = UUID ( ) . uuidString
154
+
155
+ // The token is a long string, generate a very long repeating string of characters to see how the view
156
+ // will react.
157
+ let longString = UUID ( ) . uuidString. replacingOccurrences ( of: " - " , with: " " )
158
+ identity. token = Array ( repeating: longString, count: 10 ) . reduce ( " " , + )
159
+
160
+ return identity
161
+ } ( )
162
+
133
163
static var previews : some View {
134
- ContentView ( ) . environmentObject ( Identity ( ) )
164
+ Group {
165
+ ContentView ( ) . environmentObject ( Identity ( ) )
166
+
167
+ ContentView ( ) . environmentObject ( filledIdentity)
168
+ }
135
169
}
136
170
}
137
171
@@ -144,5 +178,7 @@ struct IdentityButtonStyle: ButtonStyle {
144
178
. background ( LinearGradient ( gradient: Gradient ( colors: [ Color . blue, Color . pink] ) ,
145
179
startPoint: . leading, endPoint: . trailing) )
146
180
. cornerRadius ( 40 )
181
+ // Push the button down a bit when it's pressed.
182
+ . scaleEffect ( configuration. isPressed ? 0.9 : 1 )
147
183
}
148
184
}
0 commit comments