mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Reviewed By: bnham Differential Revision: D4250937 fbshipit-source-id: b5f2cfdeb06c04399670e463b8b2498e2fe0074b
34 lines
693 B
React
34 lines
693 B
React
// @flow
|
|
|
|
import React from 'react';
|
|
|
|
type Props = {
|
|
id: string,
|
|
dropAction: (sourceId: string, thisId: string) => void,
|
|
children?: any,
|
|
}
|
|
|
|
export default class DropTarget extends React.Component {
|
|
props: Props;
|
|
|
|
_handleDragOver = (e: SyntheticDragEvent) => {
|
|
e.preventDefault();
|
|
}
|
|
|
|
_handleDrop = (e: SyntheticDragEvent) => {
|
|
const sourceId = e.dataTransfer.getData('text');
|
|
e.preventDefault();
|
|
this.props.dropAction(sourceId, this.props.id);
|
|
}
|
|
|
|
render(): React.Element<*> {
|
|
return React.cloneElement(
|
|
React.Children.only(this.props.children),
|
|
{
|
|
onDragOver: this._handleDragOver,
|
|
onDrop: this._handleDrop,
|
|
}
|
|
);
|
|
}
|
|
}
|