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

Dan Peluso

06/21/2022, 2:32 PM
I'm looking for a component that could work for a 'popup' effect on my screen. Something where it could appear to be 'on top of' other screen components (raised z axis) but having some trouble implementing. At first I thought a Box would be good, but when that is embedded in a row and column it will resize and move other components around. I want it to appear above these components instead - is there a way to do that with a box or should I be using a different component?
for additional context - this would be something like a help box that give users context about something on the screen
l

Landry Norris

06/21/2022, 3:14 PM
Can you use Dialog or AlertDialog?
j

Joseph Hawkes-Cates

06/21/2022, 3:22 PM
I was just looking at this for my project and I took a look at the implementation of the DropDownMenu composable and found the Popup composable which it uses internally: https://developer.android.com/reference/kotlin/androidx/compose/ui/window/package-summary#Popup(androidx.compose.ui.A[…]Properties,kotlin.Function0)
I haven’t used it so can’t give you much guidance, but it seems like it could be good for what you’re looking to do
Or AlertDialog as Landry said, especially if you want the popup to be modal
l

Landry Norris

06/21/2022, 3:27 PM
Good point. I would look at Popup if you don’t need it to go away if you tap outside, and Dialog if you do. Keep in mind that AlertDialog provides an easy way to have a message and a few buttons, but Dialog is much more flexible. If AlertDialog matches what you need, it’s a great choice.
o

Oleksandr Balan

06/21/2022, 3:45 PM
We have recently build something similar for modal bottom sheet lib, check
FullscreenPopup
component. It is basically build the same as
Popup
, but lays out always fullscreen. https://github.com/oleksandrbalan/modalsheet/blob/main/modalsheet/src/main/java/eu/wewox/modalsheet/FullscreenPopup.kt
8 Views