Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DropdownMenu performs onDismissRequest twice #4080

Closed
tangshimin opened this issue Dec 29, 2023 · 0 comments · Fixed by JetBrains/compose-multiplatform-core#1057
Closed

DropdownMenu performs onDismissRequest twice #4080

tangshimin opened this issue Dec 29, 2023 · 0 comments · Fixed by JetBrains/compose-multiplatform-core#1057
Assignees
Labels

Comments

@tangshimin
Copy link

Describe the bug
Sometimes DropdownMenu executes onDismissRequest twice.
CursorDropdownMenu has the same issue.

Affected platforms

  • Desktop

Versions

  • Compose Multiplatform version: v1.5.0 ~ v1.6.0-dev1350
  • OS version(s)* (required for Desktop and iOS issues): Windows 11

To Reproduce

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Settings
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application

fun main() = application {
    Window(onCloseRequest = ::exitApplication) {
        Box(Modifier.fillMaxSize()){
            var settingsExpanded by remember { mutableStateOf(false) }
            var counter by remember { mutableStateOf(0) }
            Row(
                horizontalArrangement = Arrangement.SpaceBetween,
                verticalAlignment = Alignment.CenterVertically,
                modifier = Modifier
                    .align(Alignment.TopCenter)
                    .clickable { settingsExpanded = true }
                    .width(48.dp)
                    .height(48.dp)
            ) {
                Icon(
                    imageVector = Icons.Filled.Settings,
                    contentDescription = "",
                    tint = MaterialTheme.colors.onBackground,
                    modifier = Modifier.size(48.dp, 48.dp).padding(top = 12.dp, bottom = 12.dp)
                )
                DropdownMenu(
                    expanded = settingsExpanded,
                    onDismissRequest = {
                        settingsExpanded = false
                        counter++
                        println("DismissRequest $counter")
                    },
                ) {
                    Surface {
                        Column(Modifier.width(80.dp).height(180.dp).padding(start = 16.dp, end = 16.dp)) {
                            Text("Item 1")
                            Text("Item 2")
                            Text("Item 3")
                            Text("Item 4")
                            Text("Item 5")
                        }
                    }
                }

            }
        }
    }

}
demo.mp4
@tangshimin tangshimin added bug Something isn't working submitted labels Dec 29, 2023
@igordmn igordmn removed the p:high High priority label Feb 6, 2024
@MatkovIvan MatkovIvan self-assigned this Feb 6, 2024
MatkovIvan added a commit to JetBrains/compose-multiplatform-core that referenced this issue Feb 6, 2024
…1057)

## Proposed Changes

- Changes _internal_ API of `ComposeSceneLayer`
- Dismiss `Popup`s only on `Press` event type
- iOS platform binding will be fixed in the next PR by @dima-avdeev-jb 

## Testing

Test: Run reproduction snipped from the issue

## Issues Fixed

Fixes JetBrains/compose-multiplatform#4080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants