Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Modifier.dragAndDropSource and Modifier.dragAndDropTarget #4235

Open
igordmn opened this issue Feb 5, 2024 · 12 comments
Open

Support Modifier.dragAndDropSource and Modifier.dragAndDropTarget #4235

igordmn opened this issue Feb 5, 2024 · 12 comments
Labels
commonization enhancement New feature or request p:high High priority

Comments

@igordmn
Copy link
Collaborator

igordmn commented Feb 5, 2024

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"

@igordmn igordmn added enhancement New feature or request commonization labels Feb 5, 2024
@hakanai
Copy link

hakanai commented Apr 4, 2024

Any signs of life?

@igordmn igordmn added the p:high High priority label Apr 5, 2024
@g3th

This comment was marked as off-topic.

@yumiki

This comment was marked as off-topic.

@teewhydope

This comment was marked as off-topic.

@tunjid
Copy link

tunjid commented May 5, 2024

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

@igordmn
Copy link
Collaborator Author

igordmn commented May 6, 2024

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
Copy link

g3th commented May 9, 2024

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
Copy link

tunjid commented May 11, 2024

@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
Copy link
Collaborator Author

igordmn commented May 13, 2024

@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
Copy link

gochev commented May 14, 2024

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
Copy link

gochev commented May 14, 2024

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
Copy link

g3th commented May 14, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
commonization enhancement New feature or request p:high High priority
Projects
None yet
Development

No branches or pull requests

7 participants