Skip to content

Instantly share code, notes, and snippets.

@azamsharp
Created June 28, 2020 16:38
Show Gist options
  • Save azamsharp/ba922e83d6f16b0add34d8d9166a6c65 to your computer and use it in GitHub Desktop.
Save azamsharp/ba922e83d6f16b0add34d8d9166a6c65 to your computer and use it in GitHub Desktop.
//
// 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()
}
}
@sstadelman
Copy link

sstadelman commented Sep 20, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment