I am wondering how to deal with `pointerInput` cor...
# compose
m
I am wondering how to deal with
pointerInput
correctly in common code. I want to detect a right mouse click if the device is operated with a mouse. However, when I use the button property of the event, then I get a build time error for Android. Why? IntelliJ does not complain when I use this in common code.
Copy code
if (event.button?.isSecondary ?: false) {...}

On Android:
Unresolved reference 'isSecondary'.
Unresolved reference 'button'.
The documentation says “Specifies the pointer button state of which was changed. It has value only when event’s type is PointerEventType.Press or PointerEventType.Release and when button is applicable (only for Mouse and Stylus events).” This tells me that
button
will just be
null
in case it is not applicable. I tried this with Compose 1.9.0-rc02 and Kotlin 2.2.20 on a Mac.
e
button
is not part of common expect class PointerEvent or android actual class PointerEvent, only skiko actual class PointerEvent (which is used on non-Android targets)
are you possibly building a library that doesn't have an Android target, and then using it on Android?
🚫 1
also I think you should be able to use
Copy code
if (event.buttons.isPrimaryPressed)
instead
m
To me the API description sounds as if it is intended to be multiplatform but actually isn’t.
@ephemient Your alternative code actually worked. Thank you. I still wonder why IntelliJ code completion offered me the other code for a file in commonMain and did not complain when I used it. It was only the compiler which complained later. (The project is a multplatform library project configured for JVM, android, iOS and wasmJs.)