MasonryStack icon indicating copy to clipboard operation
MasonryStack copied to clipboard

Lazy Loading

Open lukepistrol opened this issue 2 years ago • 3 comments

I'd be nice to have the content loading lazily - meaning only the views on screen (or views that are about to be on screen) will be rendered.

Tasks

  • Is lazy loading possible using Layout protocol?
  • If so, how can MasonryStack adapt lazy loading?
  • Any other considerations?

Let me know if you want to take on this issue by commenting below.

lukepistrol avatar Aug 26 '23 11:08 lukepistrol

I implemented a similar solution with help from here - https://stackoverflow.com/questions/66101176/how-could-i-use-a-swiftui-lazyvgrid-to-create-a-staggered-grid

I was on the lookout for such solution for very long time and it looks like the solution was super easy in the end.

PankajGaikar avatar Aug 26 '23 17:08 PankajGaikar

@PankajGaikar The problem with this approach is, that it doesn't conform to the Layout protocol which is a nice-to-have when you want to have different layouts in specific contexts or want to allow the user to switch between different layouts.

lukepistrol avatar Aug 26 '23 18:08 lukepistrol

As workaround I've tried using the following code and views are being rendered lazily. But it would be better if library offers this feature.

 MasonryVStack {
    ForEach(array) { item in
        LazyVStack {
            ItemView(item)
        }
    }
}       

ltns35 avatar Jan 04 '24 20:01 ltns35