mirror of
https://github.com/ivanvorobei/SwiftUI.git
synced 2026-04-10 19:17:07 +02:00
65 lines
1.6 KiB
Swift
Executable File
65 lines
1.6 KiB
Swift
Executable File
/*
|
||
See LICENSE folder for this sample’s licensing information.
|
||
|
||
Abstract:
|
||
A view showing a scrollable list of landmarks.
|
||
*/
|
||
|
||
import SwiftUI
|
||
|
||
struct CategoryRow: View {
|
||
var categoryName: String
|
||
var items: [Landmark]
|
||
|
||
var body: some View {
|
||
VStack(alignment: .leading) {
|
||
Text(self.categoryName)
|
||
.font(.headline)
|
||
.padding(.leading, 15)
|
||
.padding(.top, 5)
|
||
|
||
ScrollView {
|
||
HStack(alignment: .top, spacing: 0) {
|
||
ForEach(self.items.identified(by: \.name)) { landmark in
|
||
NavigationLink(
|
||
destination: LandmarkDetail(
|
||
landmark: landmark
|
||
)
|
||
) {
|
||
CategoryItem(landmark: landmark)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
.frame(height: 185)
|
||
}
|
||
}
|
||
}
|
||
|
||
struct CategoryItem: View {
|
||
var landmark: Landmark
|
||
var body: some View {
|
||
VStack(alignment: .leading) {
|
||
landmark
|
||
.image(forSize: 155)
|
||
.renderingMode(.original)
|
||
.cornerRadius(5)
|
||
Text(landmark.name)
|
||
.color(.primary)
|
||
.font(.caption)
|
||
}
|
||
.padding(.leading, 15)
|
||
}
|
||
}
|
||
|
||
#if DEBUG
|
||
struct CategoryRow_Previews: PreviewProvider {
|
||
static var previews: some View {
|
||
CategoryRow(
|
||
categoryName: landmarkData[0].category.rawValue,
|
||
items: Array(landmarkData.prefix(4))
|
||
)
|
||
}
|
||
}
|
||
#endif
|