Reputation: 71
When I scroll my LazyVGrid, app lags a lot.
LazyVGrid(
columns: [
GridItem(.adaptive(minimum: horizontalSizeClass == .compact ? 160:320, maximum: 320), spacing: 16, alignment: .top)
],spacing: 16
){
ForEach(viewModel.articles){ article in
VStack{
ArticleCardView(article: article, animation: animation, show: $show)
.equatable()
ArticleCardView
VStack{
if !show {
HStack{
Text(String(format: "%.2f €", article.rate1))
.fontWeight(.heavy)
.padding(.vertical, 5)
}
Image(uiImage: readImage(name: "\(article.id)00"))
.resizable()
.scaledToFit()
I made this view Equtable, but still lags. Scroll is not fluid.
Any idea to optimize scroll.
Upvotes: 6
Views: 2508
Reputation: 2164
One thing to check is the use of an .adaptive
GridItem
. For an experiment try .flexible
- and see if it is faster.
I didn't have the scrolling lag, but noticed that SwiftUI created tiles for all my records when using .adaptive
, but acted lazily for .fixed
and .flexible
Upvotes: 0