Drag and Drop in Compose, the doc cover the draggi...
# compose
d
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
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
Thanks
a
Is it still far on the roadmap?
z
I can't say when it's gonna get done but probably not in the next few releases unfortunately.
t
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