How can I use the flow of PagingData from pager3 in a ViewPager2 to side scroll?

Viewed 67

I'm building a news app, and have successfully built the feed of news articles using pager3 (from androidx.paging). Tapping on a news article then goes to a detailed view of that article (I've used the Navigation component to do that).

The next feature we want to add is the ability to swipe left/right while viewing an article to see the next/previous article in the feed.

As each article details is a Fragment, it seemed like the right idea to look at ViewPager2, using its FragmentStateAdapter.

However, I can't seem to wire together the flow from pager3 into that adapter?

pager3 supplies an adapter for a RecyclerView (this is what I'm using in the main news feed) and ViewPager2 is built on top of a RecyclerView but requires a FragmentStateAdapter.

It seems like these two libraries are so close together they should just plug into one another, but I'm missing a bit of glue (or I'm missing some fundamental understanding Android development!)

Does anyone have any suggestions how to either make these two libraries work together, or how I should implement my swipe between articles if ViewPager2 was the wrong choice?

0 Answers
Related