Skip to content

Commit 956da25

Browse files
committed
Add layout playgrounds (Stacks, Spacer, Divider, Color, ScrollView)
1 parent 43bab17 commit 956da25

1 file changed

Lines changed: 90 additions & 0 deletions

File tree

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#if canImport(AndroidSwiftUI)
2+
import AndroidSwiftUI
3+
#else
4+
import SwiftUI
5+
#endif
6+
7+
struct StackPlayground: View {
8+
var body: some View {
9+
ScrollView {
10+
VStack(alignment: .leading, spacing: 0) {
11+
Example("VStack .leading") {
12+
VStack(alignment: .leading) { Text("Row one"); Text("Row two, longer") }
13+
}
14+
Example("VStack .trailing") {
15+
VStack(alignment: .trailing) { Text("Row one"); Text("Row two, longer") }
16+
}
17+
Example("HStack with Spacer") {
18+
HStack { Text("Start"); Spacer(); Text("End") }
19+
}
20+
Example("ZStack .center") {
21+
ZStack {
22+
Color.blue.frame(width: 220, height: 100)
23+
Text("Overlaid")
24+
}
25+
}
26+
Example("ZStack .bottomTrailing") {
27+
ZStack(alignment: .bottomTrailing) {
28+
Color.green.frame(width: 220, height: 100)
29+
Text("Corner")
30+
}
31+
}
32+
}
33+
}
34+
}
35+
}
36+
37+
struct SpacerDividerPlayground: View {
38+
var body: some View {
39+
ScrollView {
40+
VStack(alignment: .leading, spacing: 0) {
41+
Example("Spacer pushes apart") {
42+
HStack { Text("Left"); Spacer(); Text("Right") }
43+
}
44+
Example("Divider between rows") {
45+
VStack(alignment: .leading, spacing: 8) {
46+
Text("Above")
47+
Divider()
48+
Text("Below")
49+
}
50+
}
51+
}
52+
}
53+
}
54+
}
55+
56+
struct ColorPlayground: View {
57+
private let swatches: [(String, Color)] = [
58+
("blue", .blue), ("green", .green), ("orange", .orange),
59+
("purple", .purple), ("pink", .pink), ("red", .red),
60+
("yellow", .yellow), ("gray", .gray),
61+
]
62+
var body: some View {
63+
ScrollView {
64+
VStack(alignment: .leading, spacing: 0) {
65+
ForEach(swatches, id: \.0) { swatch in
66+
Example(swatch.0) {
67+
swatch.1.frame(height: 44).cornerRadius(8)
68+
}
69+
}
70+
}
71+
}
72+
}
73+
}
74+
75+
struct ScrollViewPlayground: View {
76+
var body: some View {
77+
ScrollView {
78+
VStack(alignment: .leading, spacing: 8) {
79+
Text("Scroll to see all rows")
80+
.padding()
81+
ForEach(1...40, id: \.self) { n in
82+
Text("Scrollable row \(n)")
83+
.padding()
84+
.background(n % 2 == 0 ? Color.blue : Color.orange)
85+
.cornerRadius(6)
86+
}
87+
}
88+
}
89+
}
90+
}

0 commit comments

Comments
 (0)