Skip to content

Commit c749808

Browse files
committed
Example project: Use grid for regular horizontal size class
1 parent 0945e2b commit c749808

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

FlowStackExample/FlowStackExample/ContentView.swift

+21-6
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,40 @@ import SwiftUI
99
import FlowStack
1010

1111
struct ContentView: View {
12+
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
13+
1214
let cornerRadius: CGFloat = 24
1315

1416
var body: some View {
1517
FlowStack {
1618
ScrollView {
17-
LazyVStack(alignment: .center, spacing: 24, pinnedViews: [], content: {
18-
ForEach(Product.allProducts) { product in
19-
FlowLink(value: product, configuration: .init(cornerRadius: cornerRadius)) {
20-
ProductRow(product: product, cornerRadius: cornerRadius)
21-
}
19+
Group {
20+
if horizontalSizeClass == .compact {
21+
LazyVStack(alignment: .center, spacing: 24, pinnedViews: [], content: {
22+
content
23+
})
24+
25+
} else {
26+
LazyVGrid(columns: [GridItem(.flexible(), spacing: 16), GridItem(.flexible())], alignment: .center, spacing: 16, content: {
27+
content
28+
})
2229
}
23-
})
30+
}
2431
.padding(.horizontal)
2532
}
2633
.flowDestination(for: Product.self) { product in
2734
ProductDetails(product: product)
2835
}
2936
}
3037
}
38+
39+
var content: some View {
40+
ForEach(Product.allProducts) { product in
41+
FlowLink(value: product, configuration: .init(cornerRadius: cornerRadius)) {
42+
ProductRow(product: product, cornerRadius: cornerRadius)
43+
}
44+
}
45+
}
3146
}
3247

3348
struct ContentView_Previews: PreviewProvider {

0 commit comments

Comments
 (0)