1

I have Tab Layout with multiple fragments and I would like to display a Popup only when a specific screen is being displayed. I am using the Jetpack Compose Popup component. I followed the docs and currently the popup is always being displayed regardless the fragment is being displayed, but I want to show the Popup only when a specific screen is being displayed.

Popup code:

Box {
val popupWidth = 200.dp
val popupHeight = 50.dp
val cornerSize = 16.dp

Popup(alignment = Alignment.Center) {
    // Draw a rectangle shape with rounded corners inside the popup
    Box(
        Modifier
            .size(popupWidth, popupHeight)
            .background(Color.White, RoundedCornerShape(cornerSize))
    )
}

}

Agna JirKon Rx
  • 2,321
  • 2
  • 29
  • 44

1 Answers1

0

Sorry to revive an old thread but for completeness sake, try using a boolean and an if statement that is true when you want the popup to be shown.

var showPopup by remember { mutableStateOf(false) }
val popupWidth = 200.dp
val popupHeight = 50.dp
val cornerSize = 16.dp

if (showPopup) {
    Popup(alignment = Alignment.Center, onDismissRequest = { showPopup = false }) {
        Box(modifier = Modifier.size(popupWidth, popupHeight).background(Color.white, RoundedCornerShape(cornerSize)) {
            // content
        }
    }
}