Created
March 23, 2020 19:28
-
-
Save paololeonardi/c226351b1144bd991fbbc47e732e5acb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| import WaterfallGrid | |
| let colors: [Color] = [.red, .green, .blue, .orange, .yellow, .pink, .purple] | |
| let names = (0...6).map { "Text\($0)" } | |
| let items: [Int] = (0...6).map { _ in Int.random(in: 0...6) } | |
| struct ContentView: View { | |
| var body: some View { | |
| NavigationView { | |
| WaterfallGrid((0...6), id: \.self) { index in | |
| NavigationLink(destination: Text(names[index])) { | |
| CardView(index: index) | |
| } | |
| } | |
| .gridStyle(columns: 3, spacing: 8, padding: EdgeInsets(top: 8, leading: 8, bottom: 8, trailing: 8)) | |
| .navigationBarTitle("Test") | |
| } | |
| } | |
| } | |
| struct RectangleView: View { | |
| let text: String | |
| let color: Color | |
| var body: some View { | |
| ZStack { | |
| Rectangle() | |
| .foregroundColor(color) | |
| .cornerRadius(8) | |
| Rectangle() | |
| .foregroundColor(.init(.sRGB, red: 0, green: 0, blue: 0, opacity: 0.7)) | |
| .frame(height: 30) | |
| Text(text) | |
| .foregroundColor(.white) | |
| } | |
| } | |
| } | |
| struct CardView: View { | |
| let index: Int | |
| var body: some View { | |
| VStack(spacing: 4) { | |
| RectangleView(text: names[index], color: colors[index]) | |
| .frame(height: 180) | |
| Text(names[index]) | |
| .foregroundColor(.blue) | |
| Text("\(items[index]) items") | |
| .font(.caption) | |
| .foregroundColor(.gray) | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
paololeonardi/WaterfallGrid#26