Reputation: 153
In our app, we display a large list of items (roughly 30000 items) whereby each item needs to convert a complex/long string with tags into a NSAttributedString which is then displayed. We have optimised this conversion as good as it gets, however, if the user scrolls a huge distance by grabbing the scroll indicator of the ScrollView, the app freezes completely as hundreds of items need to be "calculated" simultaneously (only to then not being shown as the user has already scrolled further).
Thus, is there a way to disable just this "grab to scroll" behaviour while maintaining the scroll indicators visible (hence, using .scrollIndicators(.hidden)
isn't an option)? Thanks!
ScrollView{
LazyVStack {
ForEach(1..<200, id:\.self) { item in
Text(String(item))
// Text(getAttributedStringForItem(item) // ⚠️ NOTE: In the real application, a time-consuming operation is performed here in order to generate a preview for the item. This operation cannot be run on a background thread (a string with tags is converted to a NSAttributedString – an operation which must be run on the main thread).
}
}
}
Edit: As someone rightly pointed out in the comments, it would be against the user's expectations to show the scroll indicators while disabling the scrolling by grabbing them. Hence, I wonder if there's a way to detect such scrolling (so that we could disable the generation of the previews during the time of scrolling)?
Upvotes: 0
Views: 36