Skip to content

Instantly share code, notes, and snippets.

@nrivard
Created April 23, 2020 14:29
Show Gist options
  • Save nrivard/3c82083bbf60b3d01271896a668fb3a2 to your computer and use it in GitHub Desktop.
Save nrivard/3c82083bbf60b3d01271896a668fb3a2 to your computer and use it in GitHub Desktop.
Multiplatform SwiftUI code that fails on macOS
import SwiftUI
struct ContentView: View {
var body: some View {
List {
ScrollySection(sectionName: "Section 1")
ScrollySection(sectionName: "Section 2")
ScrollySection(sectionName: "Section 3")
}
}
}
struct ScrollySection: View {
let sectionName: String
var body: some View {
VStack(alignment: .leading) {
Text(verbatim: sectionName)
.font(.headline)
ScrollView(.horizontal) {
HStack {
ForEach(0..<20) {
Squircle(text: "Item \($0)")
.frame(width: 100, height: 100)
}
}
}
}
}
}
struct Squircle: View {
let text: String
var body: some View {
ZStack {
RoundedRectangle(cornerRadius: 8)
.fill(Color.green)
Text(verbatim: text)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment