enyo.DragAvatar, how is this api helpful?

edited February 2014 in Enyo 2
I'm implementing drag and drop in my app. I'm wonder how can the DragAvatar be used when the control isn't even rendered until you start dragging? what good is that. If there's an element on the screen that needs dragging with events, the element is normally seen prior to dragging, right?. so am I expected to just render the control that needs dragging and then destroy it when the dragging starts, in hopes that the DragAvatar will re-render it smoothly, for the purpose of dragging?, is this the normal procedure?

Why not have a straightforward enyo.Drag, with events, position props{}, maybe axis controls and container restrictions, and a drop()? I think this would be more helpful than DragAvatar.

Comments

  • In my experience, there are issues with dragging an existing control if that control isn't already absolutely positioned within the drag region. Also, if you are dragging between containers (e.g. moving an item from one list to another), an avatar is a better way to handle it. I've specifically used it when dragging in a List which is necessary because the originating control may be destroyed during the dragging due to the flyweight pattern.
  • Hey Ryan, thanks for the response. Let's forget about List for a moment and just consider perhaps a simple div (Control) that needs to be dragged. That div would normally be seen as a regular item on the screen as it is already rendered. So my question is, what good is this DragAvatar api (for DandD purposes) if it expects the Control, the simple div in this case, to NOT already be rendered?

    After all, you want the user to see the div to know it requires dragging.
  • If the control you're dragging is sufficiently complex that you wouldn't want to drag the whole thing (either for performance or usability reasons), the avatar might be a good alternative. For example, if you were creating a Pinterest-style UX with cards consisting of titles, images, and comments in which you wanted to be able to drag a card to delete or reorder, an avatar of a card icon or thumbnail of the image would probably be a good fit versus the entire card.

    That said, I'm sure there are situations in which simply dragging an existing control around is simpler than rerendering it into an avatar to drag around instead. I think that if all you're doing is changing the position of the control, you don't need the avatar. However, if you're using DnD to ultimately alter an underlying data model, using the avatar could simplify your code at the expense of a little extra rendering.
  • Got it. It brings to mind maybe dragging a file avatar into a garbage can icon, or something of a sought.
Sign In or Register to comment.