Does anyone know how to update a recyclerview that...
# compose
g
Does anyone know how to update a recyclerview that is inside a Compose AndroidView?
This is the AndroidView that contains the recyclerview
Copy code
AndroidView(
    factory = { context ->
        val recyclerView = RecyclerView(context)
        val linearLayoutManager =
            LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)

        with(recyclerView) {
            layoutManager = linearLayoutManager
            adapter = dateSelectorAdapter
        }

        recyclerView
    },
    update = {}
)
When a
mutableState
changes in my
viewModel
ideally I would want to update the
adapter
to update the
recyclerView
z
Move your
adapter = dateSelectorAdapter
to the
update
lambda
g
Thanks @Zach Klippenstein (he/him) [MOD]! I’ll try it 😄
c
The documentation of AndroidView) may be helpful, there are a few important things to know about it, and it has guidance on how to use it properly. The docs explain that
factory
only produces the view and will only be called once, while "the update block can be run multiple times due to recomposition, and it is the right place to set View properties depending on state"
👌 1
☝🏻 1