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

DropTarget that accepts all types #432

Closed
simshaun opened this issue Apr 8, 2016 · 13 comments
Closed

DropTarget that accepts all types #432

simshaun opened this issue Apr 8, 2016 · 13 comments

Comments

@simshaun
Copy link

simshaun commented Apr 8, 2016

I'm trying to globally implement window scrolling when any DragSource is dragged close to the window's edge.

Going off of http://gaearon.github.io/react-dnd/examples-sortable-stress.html, I'm making my entire App a DropTarget whose sole purpose is to handle scrolling via the hover specification method.

What I can't figure out is how to have that DropTarget accept any type. I don't want to have to explicitly list/register every possible type at the App root. Is that currently possible? or am I going about it all wrong?

@simshaun simshaun changed the title DropTarget types wildcard for window scrolling DropTarget that accepts all types Apr 8, 2016
@froatsnook
Copy link
Collaborator

I'm not an expert, but as far as I know, this isn't possible. Even if you get the DragDropManager, you'll only find types in manager.registry.types for rendered components (the DragSource type can be a function, and this function isn't called until it's needed). One thing you could do would be to use your own DragSource that keeps track of types.

// YourComponents.js
- import { DragSource } from "react-dnd";
+ import { DragSource } from "./DragSource";
// DragSource.js
import { DragSource as ReactDnDDragSource } from "react-dnd";
var types = new Set();
export function DragSource(type, ...args) {
  types.add(type); // hopefully you're not using (props) => type
  return ReactDnDDragSource(type, ...args);
}

export function allTypes() {
  return Array.from(types);
}

@simshaun
Copy link
Author

I'm wondering if it would be better to modify DropTarget to accept a wildcard (true, *, something like that) for acceptable types. I'm just starting out with this library though, so I don't know how the internals work yet.

@froatsnook
Copy link
Collaborator

Yeah I think that would be the right solution! true would make sense and not break anyone's code who happened to use "*" as their source/target ID :).

froatsnook added a commit to froatsnook/dnd-core that referenced this issue Apr 12, 2016
froatsnook added a commit to froatsnook/dnd-core that referenced this issue Apr 12, 2016
froatsnook added a commit to froatsnook/dnd-core that referenced this issue Apr 12, 2016
froatsnook added a commit to froatsnook/dnd-core that referenced this issue Apr 12, 2016
@froatsnook
Copy link
Collaborator

Hey @simshaun,

I implemented this in dnd-core and it seems to be working. Before merging it in I need to update the tests some more, and then work on react-dnd.

@gaearon: what do you think of this change? (true acting as wildcard for DropTargets)

froatsnook added a commit to froatsnook/dnd-core that referenced this issue Apr 12, 2016
froatsnook added a commit to froatsnook/dnd-core that referenced this issue Apr 12, 2016
froatsnook added a commit to froatsnook/dnd-core that referenced this issue Apr 12, 2016
@simshaun
Copy link
Author

Cool!

@gaearon
Copy link
Member

gaearon commented Apr 14, 2016

Yep, true sounds good to me. We’ll need to document this if we add this.

@froatsnook
Copy link
Collaborator

Cool, I'll finish this up then.

@crispy-invention
Copy link

@simshaun since we have canDrop() would you please see if this issue is still valid?

@simshaun
Copy link
Author

Sorry, it's been so long I don't remember what codebase I was working in.

Looking at the docs, I'm not sure if canDrop is what's needed or not. Does that override DropTarget's types parameter?

@crispy-invention
Copy link

@simshaun you can have type = ["common"] (or all types) on DropTarget so any source can be dropped on that target. Now if canDrop() is available DnD will use it for all sources. So you can precisely control what source can be dropped and when.

@stale
Copy link

stale bot commented Sep 4, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Sep 4, 2019
@stale stale bot closed this as completed Sep 11, 2019
@m0onspell
Copy link

Sorry, it's been so long I don't remember what codebase I was working in.

Looking at the docs, I'm not sure if canDrop is what's needed or not. Does that override DropTarget's types parameter?

Looking at the docs, it doesn't seem so.

So is there any solution to that problem? I don't understand @crispy-invention suggestion.

@paztis
Copy link

paztis commented Feb 10, 2021

accept is mandatory.
if it didn't fit the the type f the dragged item, we never enter in the canDrop function
It is still a missing feature since 5 years.
There's really no way to accept all the possible types ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants