Trevor
Trevor

Reputation: 1451

How to share a RecyclerView's view pool in Jetpack Compose?

In Android, I'm doing the new Jetpack compose and trying to figure out the equivalent of sharing a viewpool across recyclerviews.

If an app has multiple recyclerviews with similar content, then you can really speed up performance by sharing the same view pool across your recyclerviews. You can create a view pool, customize it, and then set it to each of the recyclerviews. This is something I'm used to doing.

In Jetpack Compose, instead of recycler view there is LazyColumn or LazyRow. How do I share the views or compositions across different lazy lists?

Upvotes: 1

Views: 723

Answers (1)

Richard Onslow Roper
Richard Onslow Roper

Reputation: 6863

There's no such functionality available as of the current stable version, i.e., 1.1.1. You can, however, take a look at LazyLayout. It is currently available in the alpha versions of Compose, and can achieve what you require (AFAIK) if the layouts are close to each other. Basically, it will be a single Composable, which you handle the contents of, yourself. If the lists are right next to each other, just create a single LazyLayout, create two lists, add the same source to both, and you're all done. If you want to add some other Composables between lists, you'll need to merge those with this one, and render them inside the lazy layout. That's what the Compose team would likely go with, but you know... well actually you never know.

Upvotes: 1

Related Questions