A lot of sites online that demonstrate using a Lazy stack to load a lot of views use e.g. ForEach(1...100, id: \.self) { value in
to demonstrate usage. But in a production app with complex views I can't really find any resources for where and how exactly to use Lazy Stacks. For example, I have a MasterView
with many complex views as children (each View contains multiple charts which are expensive to draw). Should I use Lazy Stacks at the top level as I do below only, or should the subviews (ComplexView
s) also use Lazy Stacks in them as well? Or should the subviews use LazyStacks and MasterView
use a regular VStack? What would be most optimal from a performance (scrolling standpoint).
struct MasterView: View {
var body: some View {
NavigationView {
ScrollView {
LazyVStack {
ComplexView()
ComplexView()
ComplexView()
ComplexView()
ComplexView()
ComplexView()
}
}
}
}
}
struct ComplexView: View {
var body: some View {
VStack { //LazyVStack??
HStack { //LazyHStack??
SwiftUIChart
Text("Chart Data")
}
HStack {
SwiftUIChart
Text("Chart Data")
}
HStack {
SwiftUIChart
Text("Chart Data")
}
}
}
}