Skip to content
This repository has been archived by the owner on Jun 18, 2018. It is now read-only.

Allow listening to frames. #9

Merged
merged 2 commits into from
Dec 25, 2015
Merged

Allow listening to frames. #9

merged 2 commits into from
Dec 25, 2015

Conversation

akorchev
Copy link
Contributor

@akorchev akorchev commented Dec 4, 2015

Extracted two methods from setup and teardown that will allow me to attach the backend to an iframe. I need a DropTarget to live inside an iframe. Here is how I would do it

class Frame extends React.Component {
  static contextTypes = {
    dragDropManager: PropTypes.object.isRequired
  }
  render() {
     return <iframe></iframe>
  }
  componentDidMount() {
      const { contentDocument } = findDOMNode(this)
      this.context.dragDropManager.backend.addEventListeners(contentDocument.defaultView)
  }
  componentWillUnmount() {
      const { contentDocument } = findDOMNode(this)
      this.context.dragDropManager.backend.removeEventListeners(contentDocument.defaultView)
  }
}

@nelix
Copy link

nelix commented Dec 5, 2015

That is much simpler than I was expecting.
Do you think you could add some tests and maybe an example?

@akorchev
Copy link
Contributor Author

akorchev commented Dec 5, 2015

I can definitely create an example. Not sure how to create tests though. This is only half of the solution - the other half is to get the dragDropManager to the iframe which I will show in the example.

@akorchev
Copy link
Contributor Author

akorchev commented Dec 6, 2015

Here is the example: https://github.com/akorchev/react-dnd-cross-frame

gaearon added a commit that referenced this pull request Dec 25, 2015
Allow listening to frames.
@gaearon gaearon merged commit a0bfef0 into react-dnd:master Dec 25, 2015
@gaearon
Copy link
Member

gaearon commented Dec 25, 2015

Thanks. I don't promise to support or test this in the future but I see no harm in adding it.
👍

@gaearon
Copy link
Member

gaearon commented Dec 25, 2015

Note that I still reference window in a couple of places so this won't cover all cases. There's a couple of places where I add a mousemove listener on window, and it's important to do this lazily for better perf. I'm open to merging more PRs handling this but I won't work on it myself.

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

Successfully merging this pull request may close these issues.

3 participants