Hey everyone :android-wave: I'm trying to create ...
# compose
f
Hey everyone 👋 I'm trying to create a composable that conditionally displays either a
Column
with a search field or a
LazyColumn
with a search field (and the rest of its items). The goal is to share the same search field composable, without resetting its state. Something like:
Copy code
fun MyComposable(){
   if(condition) {
      Column{
          SearchField()
          MyLoading()
      }
   } else {
      LazyColumn{
          SearchField()
          items(...)
      }
   }
This is a simplified example of my scenario, but just so you get the idea. The issue I have is that anything remembered inside
SearchField
will be reset when switching the condition, because the compose tree structure is different. In my case I am not able to hoist the state of
SearchField
, and would like to somehow share the composition for it. I would also like to avoid using a
LazyColumn
in the first case. Is there any way to do it? Any ideas?
f
It seems exactly what I was looking for, thank you! I'll try it out and see if I find any issues 😊