Last active
October 2, 2022 14:12
-
-
Save AdamWhitcroft/af569fe0459b9b0b3e03a1402f3da943 to your computer and use it in GitHub Desktop.
Trying to diagnose why my scrollview is dropping frames when using core data
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
// Reference tweet - https://twitter.com/AdamWhitcroft/status/1576402418719281152 | |
// See bottom of gist for things I've tried, recommendations welcome | |
// Core data ScrollView: | |
// | |
// For some reason, the top bounce-back of the scroll | |
// here drops frames and looks horrible. | |
// Video here https://twitter.com/AdamWhitcroft/status/1576402418719281152 | |
NavigationView { | |
ScrollView { | |
VStack(spacing: 8) { | |
// Core data loop using a sectioned fetch request | |
ForEach(sections) { section in | |
// Section headers | |
HStack { | |
Text("\(section.id)") | |
Spacer() | |
Text("\(section.count)") | |
} | |
// Individual entries | |
ForEach(section) { entry in | |
Button { | |
currentEntry = entry | |
entryPopOverVisible.toggle() | |
} label: { | |
// Nothing fancy happening in this view. | |
// Even dummy text here instead of a view passing data | |
// into results in the same dropped frame madness | |
EntryCell(entry: entry) | |
} | |
} | |
} | |
} | |
} | |
.navigationTitle("Test") | |
.navigationBarTitleDisplayMode(.inline) | |
} | |
// Dummy data ScrollView | |
// | |
// If I use the exact same layout (minus the core data) | |
// stuff, the bounce-back animation at the top of the | |
// scroll is smooth (as it should be) | |
// Video here: https://twitter.com/AdamWhitcroft/status/1576402440878198784 | |
NavigationView { | |
ScrollView { | |
VStack(spacing: 8) { | |
// 500 dummy data views | |
ForEach((1...500), id: \.self) { | |
Text("\($0)") | |
// Some basic styles to make the cells full width and larger | |
.padding() | |
.frame(maxWidth: .infinity) | |
} | |
} | |
} | |
.navigationTitle("Test") | |
.navigationBarTitleDisplayMode(.inline) | |
} | |
// Steps I've tried: | |
// | |
// 1. Using dummy data - NO frames drop | |
// 2. Commenting out the HStack section headers - frames drop | |
// 3. Replacing `EntryCell(entry: entry)` with `Text("Hello")` - frames drop | |
// 4. Using a `@FetchRequest` instead of a `@SectionedFetchRequest` (and thus a single ForEach) - frames drop | |
// ??? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment