Skip to content

Instantly share code, notes, and snippets.

@paololeonardi
Created March 23, 2020 19:28
Show Gist options
  • Select an option

  • Save paololeonardi/c226351b1144bd991fbbc47e732e5acb to your computer and use it in GitHub Desktop.

Select an option

Save paololeonardi/c226351b1144bd991fbbc47e732e5acb to your computer and use it in GitHub Desktop.
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)
}
}
}
@paololeonardi
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment