-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenuScreen.swift
453 lines (436 loc) · 17.3 KB
/
MenuScreen.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
//
// MenuScreen.swift
// Language-Learning-App
//
// This file contains the forum screen, which is what the user first sees when they log in. They can click on posts, view notifications, and add their own post.
//
// Created by ECC Chicago on 7/26/22.
//
import SwiftUI
// information for each post
struct Post: Identifiable {
var id: String = UUID().uuidString
var name: String
var image: String
var message: String
var date: String
var index: Int
}
// creates the layout for the screen
struct MenuScreen: View {
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
// array of posts from other users
@State var posts: [Post] = [
Post(name: "Sam", image: "profileOnePic", message: "有人想一起练习中文吗?请加我!", date: "8-2-2022", index: 1),
Post(name: "Nicole", image: "profileTwoPic", message: "I'm looking for someone to practice my Spanish with before an interview. Please add/message me if you'd be interested in helping. Thank you!", date: "7-29-2022", index: 2),
Post(name: "Brian", image: "profileThreePic", message: "¿alguienpuede ayudarme a practicar para mi examen oral de español?", date: "7-27-2022", index: 3),
Post(name: "Louisa", image: "profileFourPic", message: "If anyone is available right now I'd love to practice talking in English", date: "7-20-2022", index: 4)]
var body: some View {
NavigationView {
ZStack {
VStack(alignment: .center) {
// scroll view that creates every post
ScrollView {
ForEach(posts) { index in
PostDesign(post: index)
}
}
}
.navigationBarBackButtonHidden(true)
// add post button
NavigationLink(destination: AddPost(posts: $posts), label: {
Image(systemName: "plus.circle")
.resizable()
.frame(width: 80, height: 80)
.background(Color.white)
.foregroundColor(Color(red: 0.40784313725490196, green: 0.6235294117647059, blue: 0.2196078431372549))
.clipShape(Circle())
.shadow(radius: 10)
})
.offset(x:130, y: 280)
}
.background(Color(hue: 0.256, saturation: 0.17, brightness: 0.82))
.navigationTitle("Forum")
.navigationBarTitleDisplayMode(.inline)
.navigationBarItems(
trailing: Button(action: {}, label: {
NavigationLink(destination: Notifications()) {
Image(systemName: "bell.circle")
.resizable()
.foregroundColor(Color.white)
.frame(width: 30, height: 30)
.aspectRatio(contentMode: .fit)
.offset(x: -5, y: -6)
}
})
)
}
// navigation bar customization
.onAppear {
let appearance = UINavigationBarAppearance()
appearance.backgroundColor = UIColor(Color(red: 0.40784313725490196, green: 0.6235294117647059, blue: 0.2196078431372549))
appearance.titleTextAttributes = [
.font: UIFont(name: "ArialMT", size: 30)!,
.foregroundColor: UIColor(red: 249/255, green: 246/255, blue: 239/255, alpha: 1),
]
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
}
}
}
// code to design individual posts
struct PostDesign: View {
var comment: String = ""
var post: Post
var body: some View {
NavigationLink(destination: CommentView(postScreen: post), label: {
ZStack {
VStack {
HStack {
Image(post.image)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 50, height: 50)
.clipShape(Circle())
.shadow(radius: 10)
Text(post.name)
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
}
HStack {
Text(post.message)
.multilineTextAlignment(.leading)
.frame(maxWidth: .infinity, maxHeight: 100, alignment: .leading)
}
Divider()
HStack {
Spacer()
Image("Tokki50")
.resizable()
.frame(width: 100, height: 25, alignment: .leading)
.aspectRatio(contentMode: .fit)
.offset(x: -180, y: 4)
Text(post.date)
.frame(maxWidth: 90, alignment: .trailing)
.font(.body)
.offset(x: 2, y: 4)
}
}
.font(.system(size: 24, design: .rounded))
.padding()
.background(Color.white)
.cornerRadius(8)
.shadow(radius: 2, y: 2)
}
})
.tint(.black)
}
}
// screen when user clicks on a post
struct CommentView: View {
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
let postScreen: Post
var body: some View {
ScrollView {
VStack {
HStack {
Image(postScreen.image)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 50, height: 50)
.clipShape(Circle())
.shadow(radius: 10)
Text(postScreen.name)
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
}
HStack {
Text(postScreen.message)
.multilineTextAlignment(.leading)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
}
Divider()
HStack {
Group {
Spacer()
Text(postScreen.date)
.frame(maxWidth: 150, alignment: .trailing)
}
}
}
.font(.system(size: 24, design: .rounded))
.padding()
.background(Color.white)
.cornerRadius(8)
.shadow(radius: 2, y: 2)
.navigationBarBackButtonHidden(true)
.navigationTitle("Forum Post")
.toolbar {
ToolbarItem(placement: .navigation){
Button(action: {
presentationMode.wrappedValue.dismiss()
}) {
Image(systemName: "arrow.left.circle")
.resizable()
.foregroundColor(Color.white)
.frame(width: 30, height: 30)
.aspectRatio(contentMode: .fit)
.offset(x: 10, y: -5)
}
}
}
}
.background(Color(hue: 0.256, saturation: 0.02, brightness: 0.979))
}
}
// screen to create a post
struct AddPost: View {
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
@State var postContent: String = ""
@Binding var posts: [Post]
var body: some View {
VStack {
Group {
Rectangle()
.frame(height: 10)
.foregroundColor(Color.clear)
Text("Type your post here:")
.font(.title2)
.multilineTextAlignment(.leading)
.offset(x: -75)
TextEditor(text: $postContent)
.autocapitalization(.none)
.padding()
.foregroundColor(Color.black)
.frame(width: 350, height: 300)
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(Color(red: 0.40784313725490196, green: 0.6235294117647059, blue: 0.2196078431372549), lineWidth: 3)
)
.cornerRadius(10)
}
Spacer()
}
.navigationBarTitle(("Make a Post"), displayMode: .inline)
.navigationBarBackButtonHidden(true)
.toolbar {
ToolbarItem(placement: .navigation){
Button(action: {
presentationMode.wrappedValue.dismiss()
}) {
Image(systemName: "arrow.left.circle")
.resizable()
.foregroundColor(Color.white)
.frame(width: 30, height: 30)
.aspectRatio(contentMode: .fit)
.offset(x: 10, y: -5)
}
}
}
.toolbar {
ToolbarItem(placement: .automatic){
Button(action: {
if postContent != "" {
posts.insert(appendPost(), at: 0)
presentationMode.wrappedValue.dismiss()
}
}) {
Image(systemName: "paperplane.circle")
.resizable()
.foregroundColor(Color.white)
.frame(width: 30, height: 30)
.aspectRatio(contentMode: .fit)
.offset(x: -5, y: -6)
}
}
}
}
// function that creates Post
func appendPost() -> Post {
let userPost = Post(name: "Tokki", image: "iconWBg", message: postContent, date: "8-4-2022", index: 0)
return userPost
}
}
// notifications screen
struct Notifications: View {
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
var body: some View {
ScrollView {
Group {
HStack {
Image("profileFourPic")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 50, height: 50)
.clipShape(Circle())
.shadow(radius: 10)
.offset(y:3)
Text("You were on a call with Louisa")
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
.offset(y:3)
}
.padding()
Divider()
HStack {
Image("profileFourPic")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 50, height: 50)
.clipShape(Circle())
.shadow(radius: 10)
.offset(y:3)
Text("Louisa added you")
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
.offset(y:3)
}
.padding()
Divider()
HStack {
Image("profileThreePic")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 50, height: 50)
.clipShape(Circle())
.shadow(radius: 10)
.offset(y:3)
Text("You were on a call with Brian: 40:32")
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
.offset(y:3)
}
.padding()
Divider()
HStack {
Image("profileThreePic")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 50, height: 50)
.clipShape(Circle())
.shadow(radius: 10)
.offset(y:3)
Text("Brian added you")
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
.offset(y:3)
}
.padding()
Divider()
HStack {
Image("profileOnePic")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 50, height: 50)
.clipShape(Circle())
.shadow(radius: 10)
.offset(y:3)
Text("You were on a call with Sam: 10:34")
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
.offset(y:3)
}
.padding()
Divider()
}
Group {
HStack {
Image("profileTwoPic")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 50, height: 50)
.clipShape(Circle())
.shadow(radius: 10)
.offset(y:3)
Text("You were on a call with Nicole: 1:00:43")
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
.offset(y:3)
}
.padding()
Divider()
HStack {
Image("profileTwoPic")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 50, height: 50)
.clipShape(Circle())
.shadow(radius: 10)
.offset(y:3)
Text("Missed call from Nicole")
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
.offset(y:3)
}
.padding()
Divider()
HStack {
Image("profileOnePic")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 50, height: 50)
.clipShape(Circle())
.shadow(radius: 10)
.offset(y:3)
Text("You were on a call with Sam: 40:21")
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
.offset(y:3)
}
.padding()
Divider()
HStack {
Image("profileTwoPic")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 50, height: 50)
.clipShape(Circle())
.shadow(radius: 10)
.offset(y:3)
Text("Nicole added you")
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
.offset(y:3)
}
.padding()
Divider()
HStack {
Image("profileOnePic")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 50, height: 50)
.clipShape(Circle())
.shadow(radius: 10)
.offset(y:3)
Text("Sam added you")
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
.offset(y:3)
}
.padding()
Divider()
}
}
.navigationTitle("Notifications")
.navigationBarBackButtonHidden(true)
.toolbar {
ToolbarItem(placement: .navigation){
Button(action: {
presentationMode.wrappedValue.dismiss()
}) {
Image(systemName: "arrow.left.circle")
.resizable()
.foregroundColor(Color.white)
.frame(width: 30, height: 30)
.aspectRatio(contentMode: .fit)
.offset(x: 10, y: -5)
}
}
}
}
}
struct MenuScreen_Previews: PreviewProvider {
static var previews: some View {
MenuScreen()
}
}