Skip to content

Commit

Permalink
Merge pull request react-grid-layout#70 from NSinopoli/react-grid-lay…
Browse files Browse the repository at this point in the history
…outgh-52

Fix oldItem arguments in resize/drag callbacks
  • Loading branch information
STRML committed Jun 23, 2015
2 parents c540f53 + c8ee7e5 commit 37e072e
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions lib/ReactGridLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ var ReactGridLayout = React.createClass({
activeDrag: null,
isMounted: false,
layout: utils.synchronizeLayoutWithChildren(this.props.layout, this.props.children, this.props.cols, this.props.verticalCompact),
width: this.props.initialWidth
width: this.props.initialWidth,
oldDragItem: null,
oldResizeItem: null
};
},

Expand Down Expand Up @@ -193,7 +195,8 @@ var ReactGridLayout = React.createClass({
var layout = this.state.layout;
var l = utils.getLayoutItem(layout, i);

// No need to clone, `l` hasn't changed.
this.setState({oldDragItem: utils.clone(l)});

this.props.onDragStart(layout, l, l, null, e);
},
/**
Expand All @@ -208,8 +211,7 @@ var ReactGridLayout = React.createClass({
onDrag(i, x, y, {e, element, position}) {
var layout = this.state.layout;
var l = utils.getLayoutItem(layout, i);
// Clone layout item so we can pass it to the callback.
var oldL = utils.clone(l);
var oldL = this.state.oldDragItem;

// Create placeholder (display only)
var placeholder = {
Expand Down Expand Up @@ -241,29 +243,34 @@ var ReactGridLayout = React.createClass({
onDragStop(i, x, y, {e, element, position}) {
var layout = this.state.layout;
var l = utils.getLayoutItem(layout, i);
var oldL = utils.clone(l);
var oldL = this.state.oldDragItem;

// Move the element here
layout = utils.moveElement(layout, l, x, y, true /* isUserAction */);

this.props.onDragStop(layout, oldL, l, null, e);

// Set state
this.setState({ layout: utils.compact(layout, this.props.verticalCompact), activeDrag: null });
this.setState({
layout: utils.compact(layout, this.props.verticalCompact),
activeDrag: null,
oldDragItem: null
});
},

onResizeStart(i, w, h, {e, element, size}) {
var layout = this.state.layout;
var l = utils.getLayoutItem(layout, i);

// No need to clone, item hasn't changed
this.setState({oldResizeItem: utils.clone(l)});

this.props.onResizeStart(layout, l, l, null, e);
},

onResize(i, w, h, {e, element, size}) {
var layout = this.state.layout;
var l = utils.getLayoutItem(layout, i);
var oldL = utils.clone(l);
var oldL = this.state.oldResizeItem;

// Set new width and height.
l.w = w;
Expand All @@ -283,11 +290,15 @@ var ReactGridLayout = React.createClass({
onResizeStop(i, x, y, {e, element, size}) {
var layout = this.state.layout;
var l = utils.getLayoutItem(layout, i);
var oldL = utils.clone(l);
var oldL = this.state.oldResizeItem;

this.props.onResizeStop(layout, oldL, l, null, e);

this.setState({ activeDrag: null, layout: utils.compact(layout, this.props.verticalCompact) });
this.setState({
layout: utils.compact(layout, this.props.verticalCompact),
activeDrag: null,
oldResizeItem: null
});
},

/**
Expand Down

0 comments on commit 37e072e

Please sign in to comment.