Android Drag and Drop in Jetpack Compose (with Animation) - Android Studio Tutorial with Kotlin

preview_player
Показать описание
In this video I will show you how you can build draggable and droppable items in Jetpack Compose. You will see how you can attach data to your drag items and process them after they get dropped into the right container. This will increase your user experience because it is easy and intuitive to use.

00:00 Introduction
00:43 Drag and drop logic
18:28 Building the UI and the Viewmodel

Final project in Github:

Рекомендации по теме
Комментарии
Автор

Great video for my new project. Helpfull. Thank you :)

chethantb
Автор

Thank you very much for your work I'm studying it right know and I'm enjoying it, you really teach me something!😀

justplay
Автор

this is sleek! clean!
thanks for posting, keep adding more!

sijanneupane
Автор

wow thanks a lot for providing that general idea about the drag and drop

UnkCompModer
Автор

Amazing video!! you deserve a beer for this

cuak-cuack
Автор

Wow, this was super helpful thanks! Learned quite a bit!

Crimdog
Автор

Thanks for the video!
One weird thing that I stumbled upon while doing this on my own after watching the video is that imho it seems that in DropItem, in onGloballyPositioned modifier:

if we use something like this: "dragInfo.dragPosition + dragInfo.dragOffset", instead of how it is in the video "dragPosition + dragOffset", then the modifier doesn't get triggered that much and the logic didn't work. Big issue in my opinion for a very small difference in the syntax... Though there is a chance that maybe something else was causing the issue.

Personally, I fixed the issue (onGloballyPositioned not getting called that much for me), before understanding that this was making the difference, by slightly changing the original logic...

rollebonmarquis
Автор

This deals with dragging from the same application, but what about the other two cases?
1. dragging from this application to outside
2. dragging from outside into this application

Also, when doing a drag, you usually don't immediately put the dragged content into an object. If you start dragging an image, but the drop destination is a file explorer window, then you want to export it as a file. But if you drop it into something like an image slot instead, you want the data as an image. Since you don't know what format the drop target is going to want in advance, the APIs have you declare all the types you support converting to, and then it converts later, when the drop occurs. Same goes for dragging a chunk of text - the target might only support plain text, or it might support HTML, or you might want it to save the text to a file if you drag it to a folder.

Comparing to Swing/AWT, over there, there is a fairly involved API for dealing with this stuff.

trejkaz
Автор

Simply amazing....the best part is that everything is a Wrapper, 1 drag helper class of all type of draggable Views.
Perfect!

P.S :- Please try to sound a little more awake 😄

psanavps
Автор

I'm getting an issue where my the item I've selected for dragging's offset is two positions down (I'm using a LazyColumn instead of a Row) any idea where I would make the offset adjustment?

BilalMH
Автор

How to leave the dragged object in place of the target?

trakkhor
join shbcf.ru