Midnight Guest
Midnight Guest

Reputation: 1910

Android Compose Dialog tied to parent and it's size

I have Activity with NavHost and two screens. I can switch between screens by pressing the "Screen 1" or "Screen 2" Button. On the Screen 2 I draw a Dialog like this (simplified):

@Composable
fun Screen2() {
    Box(Modifier
        .fillMaxSize()
        .background(Color.LightGray)
    ) {
        Text("Screen2", modifier = Modifier.align(Alignment.TopCenter))
        Dialog(onDismissRequest = { Log.d("Screen2","Dismissed") }) {
            Card(
                modifier = Modifier
                    .fillMaxWidth()
                    .height(200.dp)
                    .padding(16.dp),
            ) {
                Text(
                    text = "This is a minimal dialog",
                    modifier = Modifier
                        .fillMaxSize()
                        .wrapContentSize(Alignment.Center),
                    textAlign = TextAlign.Center,
                )
            }
        }
    }
}

As a result, after the click on "Screen 2" button the dialog(the dimmed area) takes all space on the screen, including outside of screen 2, and the buttons on the bottom can not be pressed anymore.

dialog takes full scren

How to create a dialog which will be tied to specific parent, and will not take space outside of it, so in my case I'll still be able to navigate between screens, and dialog will slide away together with the screen 2?

Upvotes: 0

Views: 31

Answers (0)

Related Questions