I asked this same question on StackOverflow, but I have not had a response yet, so I am going to ask about this problem here.
When using ScrollView and Canvas together, every scroll event by the scrollview causes a redraw, which is a heavy bottleneck on my view's performance, which utilizes a canvas for ~100x100 grid. Is there a way to prevent, or at least mitigate this constant redrawing for better canvas scrolling performance? It looks somewhat choppy when scrolling on very complicated canvas views, which doesn't happen in HTML.
This behavior seems to only happen with large canvases, as a ScrollView with many small Canvases do not replicate this same behavior of constant redrawing.
Here is a simple example showing that ScrollView causes lots of redraws:
import SwiftUI
var i = 0
struct ContentView: View {
var body: some View {
ScrollView([.horizontal, .vertical]) {
Canvas { _, _ in
i = i+1
print(i)
}.background(.red).frame(width: 2000, height: 2000, alignment: .center)
}
}
}
I do not believe a solution with Shape would be benifitial due to performance issues, and the overhead with using a GPU shader would be problematic with text.
I need a solution that works with iOS 15, as I am developing for older devices.