Created
June 28, 2020 16:38
-
-
Save azamsharp/ba922e83d6f16b0add34d8d9166a6c65 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// | |
// ContentView.swift | |
// Shared | |
// | |
// Created by Mohammad Azam on 6/27/20. | |
// | |
import SwiftUI | |
struct ContentView: View { | |
var columns: [GridItem] = [ | |
GridItem(.flexible()), | |
GridItem(.flexible()), | |
GridItem(.flexible()) | |
] | |
func headerView(_ index: Int) -> some View { | |
Section { | |
Text("Section \(index)") | |
.padding() | |
.foregroundColor(Color.white) | |
.font(.title) | |
.frame(maxWidth: .infinity) | |
.background(Color.blue) | |
} | |
} | |
var body: some View { | |
NavigationView { | |
ScrollView { | |
LazyVGrid(columns: columns, spacing: 10, pinnedViews: [.sectionHeaders]) { | |
ForEach(1..<11) { index in | |
Section(header: headerView(index)) { | |
ForEach(0..<20) { _ in | |
Rectangle() | |
.fill(Color.red) | |
.aspectRatio(contentMode: .fit) | |
} | |
} | |
} | |
}.padding() | |
} | |
.navigationTitle("LazyVGrid") | |
} | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's a new behavior where SwiftUI compares the UUID's for each item, which apparently creates a problem in the nested
ForEach
loops. See post.I was able to solve in your sample using the same technique.