Giter VIP home page Giter VIP logo

Comments (16)

dgrcode avatar dgrcode commented on May 6, 2024 2

Just found this thread looking for an example of using the equivalent of DataTrasnfer.setDragImage(). Links in the thread seem to be broken, so I'll put here the relevant updated links.

And using hooks:

from react-dnd.

gaearon avatar gaearon commented on May 6, 2024

I'm not 100% sure I understand your question.

Do you want to:

  1. Use custom drag image instead of default (by default, drag source is screenshotted)
  2. Change appearance of drag source and/or drop target while dragging occurs
  3. Use custom drag preview and change something in it in the middle of a drag operation

?

Do any of the examples help?

from react-dnd.

cuongcua90 avatar cuongcua90 commented on May 6, 2024

In my case, when I drag a component or node. The drag over and drag component have same styles. I must use something like this :
var node = _.extend({}, this.getDOMNode());
document.body.appendChild(node);
e.dataTransfer.setDragImage(node, e.clientX/2, this.getDOMNode().offsetHeight/2);

to show the dragging component. And set the drag over with opacity = 0 like you. But got the problem with react id.

In your code you set dataTransfer for dragPreview. But I do not know how to get it?

from react-dnd.

gaearon avatar gaearon commented on May 6, 2024

I still don't understand what you're trying to do. Maybe some screenshots would help?

from react-dnd.

cuongcua90 avatar cuongcua90 commented on May 6, 2024

I want to use custom drag preview (with custom style). And I want to know how to get dragpreview in your code. I read code and in the function beginDrag() I do not see where the dragpreview in it.

from react-dnd.

gaearon avatar gaearon commented on May 6, 2024

Do you want to hide the drag source while item is being dragged? You don't need dragPreview for that, just set opacity to 0 (or return null from render) when this.getDragState(TYPE).isDragging is true.

See this example (tick "Hide source whole dragging" checkbox): http://gaearon.github.io/react-dnd/#/drag-around-naive

Source: https://github.com/gaearon/react-dnd/blob/master/examples/_drag-around-naive/Box.js#L42

Does this help?

from react-dnd.

cuongcua90 avatar cuongcua90 commented on May 6, 2024

Thank you @gaearon. I'm writing sortable list. And I want when I drag the item we can change the style of dragging item (and also hide the drag source). For example when we drag the box in the example. We may change the border color to red.

from react-dnd.

gaearon avatar gaearon commented on May 6, 2024

@cuongcua90

I see now. Sadly it's not easily possible due to how browser D&D API works but it's something I was experimenting with in this branch. See this example (not in master).

I haven't had time to complete this, but I may be able to do so during next few weeks if it's a priority to you. Let me know if this matches what you're looking for.

Seems like a duplicate of #17.

from react-dnd.

cuongcua90 avatar cuongcua90 commented on May 6, 2024

Thank @gaearon so much. I will see your experiment and learn from it. It is exactly what I am looking for.

from react-dnd.

gaearon avatar gaearon commented on May 6, 2024

Closing this for now, as this pretty much repeats #17.
Let me know if you come up with something!

from react-dnd.

gaearon avatar gaearon commented on May 6, 2024

This is available in 0.8.0 using DragLayerMixin.

Live demo
Source code

from react-dnd.

cuongcua90 avatar cuongcua90 commented on May 6, 2024

thanks @gaearon. It works well. Just problem with performance when the drag component is complicated.

from react-dnd.

gaearon avatar gaearon commented on May 6, 2024

Just problem with performance when the drag component is complicated.

You should use PureRenderMixin (or manually implement shouldComponentUpdate) to avoid reconciling the child component on each position change. It should be fast in this case. Have you tried it?

from react-dnd.

gaearon avatar gaearon commented on May 6, 2024

Added this to docs: 6c95eb1

from react-dnd.

cuongcua90 avatar cuongcua90 commented on May 6, 2024

Better now, thanks for your support. It's very good

from react-dnd.

gaearon avatar gaearon commented on May 6, 2024

👍

from react-dnd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.