Last active
June 26, 2018 14:53
-
-
Save davidpett/38c3a99f43499c8e7df31a92645f0a41 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { View } from 'react-primitives' | |
import React, { Component } from 'react' | |
import Children from 'react-children-utilities' | |
import { DragItem, DropArea } from '../drag-drop' | |
export default class DragDrop extends Component { | |
render() { | |
const { activeDropArea, items, isDragging, position } = this.state | |
const children = Children.deepMap(this.props.children, (child, index) => { | |
if (child.type === DragItem) { | |
return React.cloneElement(child, { | |
onActivate: () => this.addItem(child), | |
onDeactivate: () => this.removeItem(child), | |
}) | |
} else if (child.type === DropArea) { | |
return React.cloneElement(child, { | |
isActive: activeDropArea === child.key, | |
isDragging, | |
onDragOver: () => this.setState({ activeDropArea: child.key }), | |
onDragOut: () => this.setState({ activeDropArea: null }), | |
position, | |
}) | |
} else { | |
return child | |
} | |
}) | |
return ( | |
<View style={{ flex: 1 }} {...this._panResponder.panHandlers}> | |
{isDragging && renderIcon(items.length, position)} | |
{children} | |
</View> | |
) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import { View } from 'react-primitives' | |
export default class DropArea extends Component { | |
render() { | |
let { isOver } = this.props | |
return ( | |
<View style={{ flex: 1 }}> | |
{this.props.children(isOver)} | |
</View> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment