Is it possible to render a Fragment inside `Compos...
# compose
k
Is it possible to render a Fragment inside
Composable
? I want to implement infinite scrolling list with database caching and I found that recyclerview suits better for this use case, thus planning to implement this view entirely in a good old fragments and xml based layouts Another solution would be calling RecyclerView using AndroidView but I'm not sure what should I go for.
a
a
You can have Fragment, or directly RecyclerView. but you should be able to implement infinite lists with LazyColumn and Paging
k
@allan.conda I tried to.. but seems like compose-paging still uses paging-alpha06 as dependency which has a bug of not appending properly... Also, the scrolling experience is not as smooth as RecyclerView I'll use paging-alpha09 in case of RecyclerView which seems to work properly and is also used the official codelab
a
Interesting, do you have link to the issue? We use paging+lazycolumn for, we got different issues but we expect the fixes to be available on the next release
k
I was facing this issue when I tried to use RemoteMediator code from the codelab with lazycolumn and it tend to refresh instead of append with that logic. Later I read it in the comments of tivi's mediator implementation about it and decided to migrate for now.
a
Ah, I see. We were using PagingSource but that’s for single source. It seems that tivi code has a workaround for it
k
@allan.conda do you have example showing use of Fragments inside Composable? I'm trying to convert this RecyclerView implementation in Compose using AndroidView but am not sure what to do with LoadStateListener callback? How can I listen to state changes in Compose world? I tried use the flow and use that as state but this requires the initial state which I don't know.
a
sorry I don’t have opensource sample I could share. you could check compose-samples how to observe and update state. You should be able to update a MutableState even from within a Fragment, you just need the reference
you could try to use a ViewModel try to access the same instance in a Composable function and from the Fragment
and update the state from there
k
In the end we'll need to collect Flow/State/MutableState using
collectAsState
extension which needs the initial value of the containing object. The RecyclerView Adapter used in paging 3 example already has the handy
Flow<CombinedLoadStateEvents>
so I guess I can simply collect this flow and mutate the viewmodel state which will trigger recomposition, am I right? The only problem is what would be the initial state.. could you please have a look at the pahing example I shared above and just nudge me in the right direction? Thanks 🙂 Any links to using Fragment inside Composable would be great cc: @allan.conda