JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.39k stars 1.12k forks source link

ModalNavigationDrawer does not close if clicked in the scrim area while not moving the mouse #4561

Closed Zenturas closed 1 week ago

Zenturas commented 3 months ago

bug can be also android related, i didnt test it

Describe the bug ModalNavigationDrawer does not close if clicked in the scrim area while not moving the mouse - also see the steps to reproduce inside the code snippet

Affected platforms

Versions

To Reproduce see code snippet

Expected behavior close drawer on scrim area

Screenshots can provide video but it is easy reproducible

Additional context

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Button
import androidx.compose.material3.DrawerState
import androidx.compose.material3.DrawerValue
import androidx.compose.material3.ModalDrawerSheet
import androidx.compose.material3.ModalNavigationDrawer
import androidx.compose.material3.Text
import androidx.compose.material3.rememberDrawerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

@Composable
fun ModalNavigationDrawerMouseClickBug() {
    val coroutineScopeState: CoroutineScope = rememberCoroutineScope()
    val drawerState: DrawerState = rememberDrawerState(DrawerValue.Closed)

    ModalNavigationDrawer(
        drawerState = drawerState,
        content = {
            Box(
                modifier = Modifier.fillMaxSize(),
                contentAlignment = Alignment.Center
            ) {
                Button(onClick = {
                    coroutineScopeState.launch {
                        drawerState.open()
                    }
                }) {
                    Text(
                        text = "1. click on this button to open the drawer (somewhere on the right to not be in the sheet area) - " +
                                "2. dont move the mouse - " +
                                "3. click again (you can click multiple times) - " +
                                "4. you see the button gets clicked (sometimes) but nothing happens - " +
                                "5. it should close the drawer, which it does if you move the mouse and" +
                                " click somewhere in the scrimed area"
                    )
                }
            }
        },
        drawerContent = {
            ModalDrawerSheet {
            }
        }
    )
}
MatkovIvan commented 3 months ago

It's related to this issue: https://issuetracker.google.com/issues/286578275

Reproducible in AOSP/Android with mouse input

MatkovIvan commented 1 week ago

Fixed in latest dev build