Skip to content

Instantly share code, notes, and snippets.

@ericlewis
Created October 25, 2019 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericlewis/a390f3919e86cdc3cdc1ea7659c4b535 to your computer and use it in GitHub Desktop.
Save ericlewis/a390f3919e86cdc3cdc1ea7659c4b535 to your computer and use it in GitHub Desktop.
"horizontal" list in SwiftUI
import SwiftUI
extension Int: Identifiable {
public var id: Self {
self
}
}
struct HList<C: RandomAccessCollection, V: View>: View where C.Element: Identifiable {
var data: C
var content: (C.Element) -> V
var body: some View {
GeometryReader { geo in
List(self.data) { i in
HStack {
Spacer()
self.content(i)
.rotationEffect(.degrees(90))
Spacer()
}
}
.frame(width: geo.frame(in: .local).height,
height: geo.frame(in: .local).width)
.rotationEffect(.degrees(-90))
}
}
}
struct ContentView: View {
var body: some View {
HList(data: 0...1000) { i in
VStack {
Image(systemName: "gear")
.imageScale(.large)
Text("niiiice \(i)")
}
// needs to be hard coded, or the sizes will be incorrect.
.frame(height: 150)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment