Hi, is there an existing Modifier function that mo...
# compose
o
Hi, is there an existing Modifier function that monitors mobile phone long press and right mouse button on desktop or web? If not, is this the best way to do it?
Copy code
expect fun Modifier.onTriggerContextMenu(onTrigger: () -> Unit): Modifier

// mobile
actual fun Modifier.onTriggerContextMenu(onTrigger: () -> Unit): Modifier =
    this then pointerInput(Unit) {
        detectTapGestures(
            onLongPress = { onTrigger() }
        )
    }

// desktop
@OptIn(ExperimentalFoundationApi::class)
actual fun Modifier.onTriggerContextMenu(onTrigger: () -> Unit): Modifier =
    this then pointerInput(Unit) {
        detectTapGestures(
            matcher = PointerMatcher.mouse(PointerButton.Secondary),
            onPress = { onTrigger() },
        )
    }