Has anyone tried creating a desktop/Android select...
# compose-desktop
m
Has anyone tried creating a desktop/Android selectable listitem? On Android, that would normally be triggered by long press. On Desktop, should check when someone is clicking to see if they are also holding shift and/or ctrl key. Googling / github search didn't yield much
j
Isnt it possible just detect regular keyboard chars pressed in Compose for desktop? Check if whatever combo pressed, and if user has that hold in and also click/long click they get multi selected?
Copy code
Box(
    Modifier
        .onKeyEvent {
            if (it.isShiftPressed) {
                true
            } else {
                false
            }
        }
        .focusable()
)
m
It is possible to get key events - but here we are talking about both keyboard and mouse
Pressing shift on its own is not a keyboard event
j
Pressing shift on its own, why isnt that a key event? Mouse is just a touch event can combine with key events?
m
Shift is a modifier key
hence it being represented by isShiftPressed
If I type "M" - you wouldn't expect two events (one for shift, another for m). You'd get one event with isShiftPressed set accordingly
👍 1
j
From what I recall, can combine LocalWindowInfo.current.keyboardModifiers and stuff like PointerMatcher.mouse(PointerButton.Secondary)
👍 1
m
Thank you! LocalWindowInfo would work. Can be checked when I get the click event
m
Just found the same...
j
But yeah its a little problematic smartphones and desktop not behaves same, no real difference imo. For me mouse is like regular touch events, with extra applied hover variant vs long pressed. Odd CMP not offers a crossover API merging these into one, with smart modifiers of multi combinations.
Implementing Multi select composable I guess would need to have expect/actual and overload desktop variant for this scenario.
m
It's going to be interesting...
Indeed it would be nice to have something to wrap these generic differences between platforms... whether it is an email list, file list, shopping list, etc. the use case is pretty much the same
a
Umm, you do get a key pressed/released event when pressing/releasing SHIFT.
And also you have
PointerEvent.keyboardModifiers.isShiftPressed
m
I haven't gotten quite that far yet... dealing with showing the selection background on a ListItem
j
I guess already looked at it, but can use Modifier.selectable on lets say Cards to make them selectable btw. The tricky part imo is to remember the items selected once sending information forward, especially if you also offer re-ordering while multi select at the same time. Did this a couple of times, and it beats me everytime 😄
m
One tricky part is the item is both clickable normally (e.g. clicking the item in the list goes to the detail screen) and selectable (if using a long press on Android or shift/ctrl click on desktop)
j
Yeah and next madness think is scrolling the list, so need to detect if actually click/longpress. And also click to close the selectable mode 😄
But I think would be possible to combine custom Modifier, like Modifier.multiSelect which detecting either long press or cmd/control/shift + click. I think that could work in commonMain actually, as they will not intefere, and would make sense having in smartphone as you can use like BLE keyboard on your smartphone as well 😄 Like shift click could work in Android as well.
m
Yes, you're right, Android can work with a mouse and keyboard. Have done that. Feels like using a computer for a bit. But user expectations when it comes to handling keyboard input seem more forgiving
j
Then we having Touchpad as well, with multi touch gestures for desktop to act similar to smartphones 😜