https://kotlinlang.org logo
#compose-desktop
Title
# compose-desktop
a

Ahmad Daneshvar

07/28/2022, 3:11 PM
Hi guys, I had question regarding mouse click consuming in the Box. I wanted to simulate the
modal
behavior with a semi transparent background (Look at the attached). I have two Boxes that one of them contains other one. In the first box I have some
focusable
and
Clickable
items (Like button, textfield … ). When I show the second box over first box (Like a modal), the components in the first box is still clickable. The desired behavior is, when box2 overlays box1 and it content, I want box2 consumes mouse clicks and input functionalities from box1. I don’t know how it is possible. Should I handle the mouse clicks manually in the modal? Should i disable all components in the Box1 manually? Thank you for your help in advance.
For those with the same problem, I’ve found a solution that works like a charm. Just add this modifier the component that you want it to consume the clicks:
Modifier.mouseClickable{}
Also, it’s need to transfer the focus to the one of modal items. You can do this by the
focusRequester
and then call
focusRequester.requestFocus
on it. By this way you can open new custom modal and transfer focus from main window to it. Thats it!
Forgot to mention, for low level interception, Instead of
Modifier.mouseClickable
, use this one:
Modifier.onPointerEvent(PointerEventType.Press, pass = PointerEventPass.Main) { /* Click closure */}
a

Afzal Najam

08/24/2022, 7:58 PM
Is there no Dialog API? It would be better to use that as this would require extra steps to ensure that it is accessible.
3 Views