JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.17k stars 1.11k forks source link

Support `Modifier.dragAndDropSource` and `Modifier.dragAndDropTarget` #4235

Open igordmn opened 4 months ago

igordmn commented 4 months ago

It was merged from Jetpack Compose 1.6: https://android-developers.googleblog.com/2024/01/whats-new-in-jetpack-compose-january-24-release.html See "Drag and drop"

hakanai commented 2 months ago

Any signs of life?

g3th commented 1 month ago

Absolutely dreadful.

This framework has been in development since 2020, and yet something as basic as OnDragListener with DragEvents for Desktop is missing. Implementing drag-and-drop on Compose Desktop is an absolute nightmare, and something as simple as a jigsaw puzzle results in convulted, terrible code to maintain.

What have you guys been doing for 4 years? 'Styling'? This framework is just a toy, the multiplatform promise is still a lie, and working on anything more interesting than trivial news/blog/reading apps is currently not worth it.

yumiki commented 1 month ago

Absolutely dreadful.

This framework has been in development since 2020, and yet something as basic as OnDragListener with DragEvents for Desktop is missing. Implementing drag-and-drop on Compose Desktop is an absolute nightmare, and something as simple as a jigsaw puzzle results in convulted, terrible code to maintain.

What have you guys been doing for 4 years? 'Styling'? This framework is just a toy, the multiplatform promise is still a lie, and working on anything more interesting than trivial news/blog/reading apps is currently not worth it.

Are you serious, guy? I understand you're angry, but this is a complex open-source project. There are a ton of things to do or fix, as you may know in software development we need to prioritize. If you feel that it is too slow, you can try to contribute.

I'm waiting for this feature too. You can see that it as been prioritize.

teewhydope commented 1 month ago

Absolutely dreadful.

This framework has been in development since 2020, and yet something as basic as OnDragListener with DragEvents for Desktop is missing. Implementing drag-and-drop on Compose Desktop is an absolute nightmare, and something as simple as a jigsaw puzzle results in convulted, terrible code to maintain.

What have you guys been doing for 4 years? 'Styling'? This framework is just a toy, the multiplatform promise is still a lie, and working on anything more interesting than trivial news/blog/reading apps is currently not worth it.

You sound entitled.

tunjid commented 1 month ago

Do you have a contribution guide? I wrote the DragAndDropSource and DragAndDropTarget implementation for Android and would like to add the desktop one.

igordmn commented 1 month ago

We don't have a contribution guide, but the usual process is to just ask in the issue before contribution.

This issue is important, so we'll gladly review/accept contribution.

The PR should be done to https://github.com/JetBrains/compose-multiplatform-core repo (see the PR template when you create the PR)

  1. If it requires a new API, better to agree on the API first.

  2. There is desktop-only API Modifier.onExternalDrag, which fully or partially covers dragAndDropTarget, all functionality of it should be merged to the new API, and the old one should be deprecated.

g3th commented 1 month ago

Do you have a contribution guide? I wrote the DragAndDropSource and DragAndDropTarget implementation for Android and would like to add the desktop one.

It would be great if you could speed up proceedings, although drag and drop is still perfectly implementable with pointerInput detectDragGestures and state holders, like compositionLocalOf. It is just more code to implement drag and drop without something like View.DragListener for desktop.

I hope these features come soon.

tunjid commented 1 month ago

@igordmn I'm familiar with using repo to contribute to androidx, is the same process used for the multiplatform fork? I just need to checkout the multiplatform branch?

igordmn commented 1 month ago

@igordmn I'm familiar with using repo to contribute to androidx

https://github.com/JetBrains/compose-multiplatform-core doesn't use/require repo. You just clone it, open in IDEA/Android Studio, and make a PR via GitHub.

gochev commented 1 month ago

g3th is there a basic guide/example how to implement it via pointerInput ? I am migrating an android jetpack compose project to kotlin multiplatform compose and this is a huge blocker.

gochev commented 1 month ago

Ok I guess you meant this ;

.pointerInput(Unit) {
                        detectDragGestures { change, dragAmount ->
                            change.consume()
                            offsetX += dragAmount.x
                            offsetY += dragAmount.y
                        }
                    }

which is fine and works but in this case you cannot drag the composable outside of the surrounding composable.. if you want to drag and drop into a target somewhere else like explained here : https://canopas.com/how-to-drag-and-drop-using-modifier-drag-and-drop-source-target-jetpack-compose its not possible

g3th commented 1 month ago

Ok I guess you meant this ;

.pointerInput(Unit) {
                        detectDragGestures { change, dragAmount ->
                            change.consume()
                            offsetX += dragAmount.x
                            offsetY += dragAmount.y
                        }
                    }

which is fine and works but in this case you cannot drag the composable outside of the surrounding composable.. if you want to drag and drop into a target somewhere else like explained here : https://canopas.com/how-to-drag-and-drop-using-modifier-drag-and-drop-source-target-jetpack-compose its not possible

Hi gochev,

I am not sure I have understood what you mean correctly.

It is possible to create an event listener without using these newly implemented modifiers dragAndDropSource and dragAndDropTarget; I have done this using a state holder in a "match the shape" game. These values are held and passed between composable via compositionLocalOf, so that recomposition can occur. https://github.com/MatthiasKerat has implemented a similar example very efficiently. However, the code is convoluted and it would be much simpler to do using Modifier.dragAndDropTarget. It is also tricky to pass values between composables, as the docs indicate composables should be free of side-effects unless there are particular cases (i.e. in the case of state hoisting).

If you meant accepting drag and drop events which begin from outside the GUI (i.e. dropping a desktop textfile into your GUI, like you would drop into your browser) then I am not sure it is possible yet.