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

Rak

01/19/2022, 4:20 PM
Hi, how would I use compose for a
DialogFragment
?
t

Tgo1014

01/19/2022, 4:26 PM
In my case I just created a AlertDialog and set the view as the compose view. Not sure if it’s the perfect approach but worked fine.
🙌 1
r

Rak

01/19/2022, 4:27 PM
so you created an xml file which contained the composeView element?
t

Tgo1014

01/19/2022, 4:33 PM
No, you can create the compose view Programatically
Copy code
val dialogView = ComposeView(requireContext()).apply {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
            setContent {
// Your Compose stuff
}
}
t

Tgo1014

01/19/2022, 4:49 PM
In my case I had to keep the “compatibility” to call a composable “dialog content” from a DialogFragment, not sure about Rak case
20 Views