https://kotlinlang.org logo
#compose
Title
# compose
l

lesincs

12/26/2021, 4:41 PM
How to call a composable function in a
LazyListScope
?
Copy code
@Composable
fun Page() {
 // I have to put the Dialogs at least the same level of LazyColumn.
 Dialogs()
 LazyColumn {
   item {
     // some item
   }
   reusableItems()
 }
}

private fun LazyListScope.reusableItems() {
 items {
   // reusable item
 }

 // it will complain because we are not in a composable scope
 Dialogs()
}
In the code above, the
Dialogs
is a normal composable function which is strongly related to the
reusableItems
. But I just can’t put it in the
reusableItems
, because it’s not in a context of composable function. So I have to move the
Dialogs
out to the level which is at least as same as the`LazyColumn`’s. It works, but breaks the encapsulation. Is there an elegant way to handle this situation?
a

Ali Albaali

12/27/2021, 10:20 AM
You can wrap the second
Dialogs
call in
item
block.
l

lesincs

12/27/2021, 10:29 AM
You can wrap the second 
Dialogs
 call in 
item
 block.
I’ve thought about it. But it’s a
LazyColumn
instead of a
Column
, so I think the item might be disposed when I scroll up.
a

Ali Albaali

12/27/2021, 10:30 AM
What about
stickyHeader
l

lesincs

12/27/2021, 10:35 AM
I think it should have the same issue, I might have multiple
stickyHeaders
.
61 Views