dbaelz
08/06/2021, 7:09 PMContextMenuDataProvider
work on every Composable and show menu (with custom entries) on right click? Doesn't work for me on Text, but works fine (with defaults) on TextField. Tested with alpha 2 and alpha3. Code in 🧵dbaelz
08/06/2021, 7:10 PM@ExperimentalComposeUiApi
@ExperimentalFoundationApi
@Composable
fun ExampleContextMenu() {
ContextMenuDataProvider(
items = {
listOf(
ContextMenuItem("Item 1") {},
ContextMenuItem("Item 2") {}
)
}
) {
Box {
Text("No menu on right click")
}
Text("No menu on right click")
TextField("Menu with default entries shown", {})
}
}
Alexander Kurasov[JB]
08/09/2021, 10:34 AM@ExperimentalComposeUiApi
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun contextMenuDemo() {
DesktopMaterialTheme {
Column {
ContextMenuDataProvider(
items = {
listOf(
ContextMenuItem("Item 1") {},
ContextMenuItem("Item 2") {}
)
}
) {
TextField("Hello non-editable", {})
SelectionContainer {
Text("Hello World!")
}
}
ContextMenuArea(items = {
listOf(
ContextMenuItem("Item 1") {},
ContextMenuItem("Item 2") {}
)
}) {
Box(modifier = Modifier.background(Color.Blue).height(100.dp).width(100.dp)) {
}
}
}
}
}
dbaelz
08/10/2021, 8:27 PMContextMenuArea
in the Compose source code. When I change my example and use the ContextMenuArea
instead of the ContextMenuDataProvider
it works like charm.Alexander Kurasov[JB]
08/11/2021, 1:28 PM