Created
October 25, 2019 20:40
-
-
Save ericlewis/a390f3919e86cdc3cdc1ea7659c4b535 to your computer and use it in GitHub Desktop.
"horizontal" list in SwiftUI
This file contains 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 | |
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