/
ContentViewViewBuilder.swift
70 lines (60 loc) · 1.57 KB
/
ContentViewViewBuilder.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
//
// ContentView.swift
// SwiftUI Tutorial: Create Child Views with ViewBuilder
//
// Created by Alvin Sosangyo on 12/18/22.
//
import SwiftUI
struct ContentView: View {
var body: some View {
VStack(spacing: 0) {
SelectionItem {
Text("You can place any View here.")
}
SelectionItem {
VStack {
Text("You can place")
Text("any View here.")
}
}
SelectionItem {
HStack {
Group {
Image(systemName: "sunrise")
Image(systemName: "sun.max")
Image(systemName: "sunset")
}
.font(.system(size: 25))
}
}
}
}
} // ContentView
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct SelectionItem<Content: View>: View {
@ViewBuilder var content: () -> Content
var body: some View {
HStack {
content().padding()
Spacer()
arrowToRight()
}
.frame(height: 60)
.frame(maxWidth: .infinity)
.background(Color.white)
.border(.black)
.shadow(radius: 5)
.padding()
}
@ViewBuilder
private func arrowToRight() -> some View {
Image(systemName: "arrow.right")
.font(.system(size: 25))
.foregroundColor(.black)
.padding()
}
}