Home > OS >  Any modifier to make ScrollView perform more flexible like List?
Any modifier to make ScrollView perform more flexible like List?

Time:07-17

I'm still new in SwiftUI. I want to know how can I make my ScrollView perform more flexible like List. You see the item inside List its even only triggered when item appears on screen so it improves my app performance better but I do not like the look of List I want to use ScrollView as replacement. Is there anyway I could replicate this feature?

 struct Content: View {
  let tempoList: [String] = ["Mark", "Bill", "John", "Jeff", "Andrew"]
  var body: some View {
    List(tempoList, id: \.self) { _ in
        ForEach(tempoList, id: \.self) { name in
            Text("\(name)")
                .onAppear {
                    print(name)
                }
        }
    }
   }
  }

CodePudding user response:

Use "Lazy" container to achieve this. Try this code below:

    ScrollView {
        LazyVStack { //this
            ForEach(0...100, id: \.self) { index in
                Text("\(index)")
                    .onAppear {
                        print(index)
                    }
            }
        }
    }
  • Related