https://kotlinlang.org logo
#compose
Title
# compose
d

Daniele Segato

03/09/2022, 5:11 PM
Drag and Drop in Compose, the doc cover the dragging part but say nothing about the "dropping" part. Say you have an active area where you want to drop another content and you want to check if the item being dragged is on top of it.. Is there any better / recommended way than using
Modifier.onGloballyPositioned
on the source / target layouts and the drag offset to check if they are within bounds? Any API that makes the process easier? Maybe something like Flutter AnchorStrategy / DragTarget?
z

Zach Klippenstein (he/him) [MOD]

03/09/2022, 5:31 PM
You probably want to use
onPlaced
instead of
onGloballyPositioned
for this sort of thing, it's much cheaper.
We don't have any apis for this in compose yet, but it's on the roadmap.
If you’re trying to build this yourself, I threw together a simple prototype a while back you could start from: https://android-review.googlesource.com/c/platform/frameworks/support/+/1958269
👍 1
d

Daniele Segato

03/10/2022, 2:06 AM
Thanks
a

allan.conda

03/10/2022, 1:20 PM
Is it still far on the roadmap?
z

Zach Klippenstein (he/him) [MOD]

03/10/2022, 3:15 PM
I can't say when it's gonna get done but probably not in the next few releases unfortunately.
t

Tunji Dahunsi

03/10/2022, 5:40 PM
Here's an example based on Zach's code that retrieves the uris from the images dropped and displays them with coil: https://github.com/tunjid/me/tree/main/common/core-ui/src/commonMain/kotlin/com/tunjid/me/core/ui/dragdrop
And a gif of the result
👏🏻 1
4 Views