https://kotlinlang.org logo
#compose-web
Title
# compose-web
j

Jan

11/12/2023, 11:30 AM
is it possible to handle right clicks on Compose Web? I only found solutions that work on JVM
z

zsmb

11/13/2023, 8:17 AM
I didn't find a high-level API for it, but if you're willing to dig into the pointer events, you can find the info. Quick and probably not perfect code example:
Copy code
Modifier.pointerInput(Unit) {
    awaitPointerEventScope {
        while (true) {
            val event = awaitPointerEvent()
            val nativeEvent = event.nativeEvent
            if (nativeEvent is SkikoPointerEvent) {
                if (nativeEvent.button == SkikoMouseButtons.RIGHT && nativeEvent.kind == SkikoPointerEventKind.UP) {
                    event.changes.forEach { it.consume() } // or similar, would need to check if this works nicely with other registered listeners
                    println("Right click!")
                }
            }
        }
    }
}
j

Jan

11/13/2023, 10:38 AM
that works perfectly, thanks! Hope this will get easier in a release
z

zsmb

11/13/2023, 10:44 AM
I've added a comment about this on this issue, which is mostly about desktop, but web support can probably also be tracked on it, until someone says otherwise
3 Views