-
Notifications
You must be signed in to change notification settings - Fork 0
/
DocumentationBootcamp.swift
77 lines (67 loc) · 2.05 KB
/
DocumentationBootcamp.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
//
// DocumentationBootcamp.swift
// SwiftfulThinkingBootcamp
//
// Created by enesozmus on 12.05.2024.
//
import SwiftUI
struct DocumentationBootcamp: View {
// MARK: PROPERTIES
@State var data: [String] = [
"Apples", "Oranges", "Bananas"
]
@State var showAlert: Bool = false
// ENES - Working copy - things to do:
/*
1) Fix title
2) Fix alert
*/
// MARK: BODY
var body: some View {
// opt + cmd + left
NavigationStack { // START: NAV
ZStack {
// background
Color.red.ignoresSafeArea()
// foreground
foregroundLayer
.navigationTitle("Documentation")
.navigationBarItems(trailing: Button("ALERT", action: {
showAlert.toggle()
}))
.alert(isPresented: $showAlert, content: {
getAlert(text: "This is the alert!")
})
}
} // END: NAV
}
/// This is the foreground layer that holds a scrollView.
private var foregroundLayer: some View {
ScrollView { // START: SCROLLV
Text("Hello")
ForEach(data, id: \.self) { name in
Text(name)
.font(.headline)
}
} // END: SCROLLV
}
// MARK: FUNCTIONS
/// Gets an alert with a specified title.
///
/// This function creates and returns an alert immediately. The alert will have a title based on the text parameter but it will NOT have a message.
/// ```
/// getAlert(text: "Hi") -> Alert(title: Text("Hi"))
/// ```
///
/// - Warning: There is no additional message in this Alert.
/// - Parameter text: This is the title for the alert.
/// - Returns: Returns an alert with a title.
/// control + click -> add doc.
func getAlert(text: String) -> Alert {
return Alert(title: Text(text))
}
}
// MARK: PREVIEW
#Preview {
DocumentationBootcamp()
}