2

I have the following code:

struct ContentView: View {

    var columnGridItems = [
        GridItem(.flexible()),
        GridItem(.flexible()),
        GridItem(.flexible()),
        GridItem(.flexible())
    ]
    
    @State var items = [Int]()
    
    var body: some View {
        
        GeometryReader { geo in
                let w = geo.size.width / 4
                ScrollView {
                    LazyVGrid(columns: columnGridItems, alignment: .center, spacing: 2) {
                        ForEach(items, id:\.self) { i in
                            CellViewS(i: i)
                                .frame(width:w, height:w)
                        }
                    }
                }
                .background(.red)
                .onAppear {
                    for i in 0..<100 {
                        items.append(i)
                    }
                }
                
            }    

    }


}

struct CellView:View {
    
    let i:Int
    
    var body: some View {
        
        ZStack {
                
            RoundedRectangle(cornerRadius: 10)
                .fill(.black)
                .padding(5)
                
                Text("SOME TEXT")
                    .foregroundColor(.white)
            
        }
        
    }
    
}

Very simple. On an iPad Pro (12.9-inch) (3rd generation) runs smooth. On an iPad Pro (12.9-inch, 2nd generation) (Model A1670) it jitters. Both running on iOS 16.1 (20B82).

At first I thought it had to do with parts of my app and a bunch of different views I do have in the cell. So I simplified the code down as much as I could to see if even the simplest implementation would cause jitter on the 2nd gen iPad or not.

I also tried to record a video of the two models but it does not show up too well on video so I gave up on that.

Is there a way to make the scroll smoother on older iOS models then? Does this mean that SwiftUI scroll views etc... are simply not going to work well on older model iPads? UIScrollView and UIKit in general scrolls great even with very heavy logic in cells etc.

Does anyone have a fix to improve scroll performance of this code on older iOS devices models?

zumzum
  • 17,984
  • 26
  • 111
  • 172
  • The iPad 2 is 11 years old. Very confusing wording you have here, going back and forth between Pro and not. I have the one I think you're actually asking about and don't have the problem. –  Oct 29 '22 at 23:08
  • Not sure what is confusing, but if you feel so I guess it is. All I am saying is that this code jitters on iPad Pro (12.9-inch, 2nd generation) (Model A1670) running – zumzum Oct 29 '22 at 23:44
  • "iPad" is the name of a product, and a product line. That's bad work on Apple's part but we have to work with it. Your question used to say "iPad 2nd gen" before I edited it. And you still have wording for both product lines in your question. That is low effort to communicate so I voted it down. –  Oct 30 '22 at 01:56
  • all cool. Thanks for making the question better. Found others that had poor performance. They were running IOS 15. I still get poor performance on iOS 16 as outlined... running UICollectionView in contrast runs super fast. Too bad this is the state things. https://stackoverflow.com/questions/56466306/uicollectionview-and-swiftui/62563798#comment131088935_62563798 – zumzum Oct 30 '22 at 02:11

0 Answers0