|
| 1 | +#if canImport(AndroidSwiftUI) |
| 2 | +import AndroidSwiftUI |
| 3 | +#else |
| 4 | +import SwiftUI |
| 5 | +#endif |
| 6 | + |
| 7 | +struct ListPlayground: View { |
| 8 | + @State private var rows = (1...25).map(CatalogRow.init) |
| 9 | + var body: some View { |
| 10 | + List(rows) { row in |
| 11 | + Text(row.title) |
| 12 | + } |
| 13 | + .refreshable { |
| 14 | + try? await Task.sleep(for: .seconds(1)) |
| 15 | + rows.insert(CatalogRow(id: rows.count + 1), at: 0) |
| 16 | + } |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +struct CatalogRow: Identifiable { |
| 21 | + let id: Int |
| 22 | + var title: String { "Row \(id)" } |
| 23 | +} |
| 24 | + |
| 25 | +struct GridPlayground: View { |
| 26 | + var body: some View { |
| 27 | + ScrollView { |
| 28 | + VStack(alignment: .leading, spacing: 0) { |
| 29 | + Example("Three fixed columns") { |
| 30 | + LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible()), GridItem(.flexible())]) { |
| 31 | + ForEach(1...9, id: \.self) { n in |
| 32 | + Text("\(n)").padding().background(Color.blue).cornerRadius(6) |
| 33 | + } |
| 34 | + } |
| 35 | + } |
| 36 | + Example("Adaptive columns") { |
| 37 | + LazyVGrid(columns: [GridItem(.adaptive(minimum: 80))]) { |
| 38 | + ForEach(1...8, id: \.self) { n in |
| 39 | + Text("Item \(n)").padding().background(Color.orange).cornerRadius(6) |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | + Example("Two rows, horizontal") { |
| 44 | + LazyHGrid(rows: [GridItem(.flexible()), GridItem(.flexible())]) { |
| 45 | + ForEach(1...8, id: \.self) { n in |
| 46 | + Text("Cell \(n)").padding().background(Color.green).cornerRadius(6) |
| 47 | + } |
| 48 | + } |
| 49 | + .frame(height: 160) |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +struct ModifierPlayground: View { |
| 57 | + var body: some View { |
| 58 | + ScrollView { |
| 59 | + VStack(alignment: .leading, spacing: 0) { |
| 60 | + Example("Padding") { Text("Padded").padding().background(Color.blue) } |
| 61 | + Example("Frame 200x60") { Text("Fixed").frame(width: 200, height: 60).background(Color.green) } |
| 62 | + Example("Background") { Text("Colored").padding().background(Color.orange) } |
| 63 | + Example("Corner radius") { Text("Rounded").padding().background(Color.purple).cornerRadius(16) } |
| 64 | + Example("Offset") { Text("Shifted").offset(x: 30, y: 0).background(Color.red) } |
| 65 | + Example("Rotation") { Text("Rotated").padding().background(Color.yellow).rotationEffect(.degrees(15)) } |
| 66 | + Example("Scale") { Text("Scaled").padding().background(Color.pink).scaleEffect(1.4) } |
| 67 | + Example("Opacity") { Text("Faded").padding().background(Color.blue).opacity(0.4) } |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | +} |
0 commit comments