Skip to content

Commit bbdecf1

Browse files
committed
Fix nasty bug where all Panes could end up sharing the same static style
If you don't specify an explicit style prop for Panes, then the Object.assign in the motion cycle assigns to the static default {} object shared by all Panes. This causes all the Panes to jump to the same position and overlap. This seems only noticeable if you disable effects. The fix is to clone the Pane's style property rather than direct-manipulating it. Also remove a needless spring interpolation if you have disabled effects.
1 parent 3498db2 commit bbdecf1

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/index.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,8 @@ class SortablePane extends Component {
363363
y: !this.isHorizontal() ? mouse : 0,
364364
}
365365
: {
366-
scale: spring(1, springConfig),
367-
shadow: spring(0, springConfig),
366+
scale: disableEffect ? 1 : spring(1, springConfig),
367+
shadow: disableEffect ? 0 : spring(0, springConfig),
368368
x: this.isHorizontal() ? springPosition : 0,
369369
y: !this.isHorizontal() ? springPosition : 0,
370370
};
@@ -376,6 +376,21 @@ class SortablePane extends Component {
376376
const onTouchStart = this.handleTouchStart.bind(this, i, x, y);
377377
const onResizeStart = this.handleResizeStart.bind(this, i);
378378
const onResizeStop = this.handleResizeStop.bind(this, i);
379+
380+
// take a copy rather than direct-manipulating the child's prop, which violates React
381+
// and causes problems if the child's prop is a static default {}, which then will be
382+
// shared across all children!
383+
var customStyle = Object.assign({}, child.props.style);
384+
Object.assign(customStyle, {
385+
boxShadow: `rgba(0, 0, 0, 0.2) 0px ${shadow}px ${2 * shadow}px 0px`,
386+
transform: `translate3d(${x}px, ${y}px, 0px) scale(${scale})`,
387+
WebkitTransform: `translate3d(${x}px, ${y}px, 0px) scale(${scale})`,
388+
MozTransform: `translate3d(${x}px, ${y}px, 0px) scale(${scale})`,
389+
MsTransform: `translate3d(${x}px, ${y}px, 0px) scale(${scale})`,
390+
zIndex: i === lastPressed ? 99 : i, // TODO: Add this.props.zIndex
391+
position: 'absolute',
392+
});
393+
379394
return (
380395
<Resizable
381396
customClass={child.props.className}
@@ -396,15 +411,7 @@ class SortablePane extends Component {
396411
minHeight={child.props.minHeight}
397412
maxWidth={child.props.maxWidth}
398413
maxHeight={child.props.maxHeight}
399-
customStyle={Object.assign(child.props.style, {
400-
boxShadow: `rgba(0, 0, 0, 0.2) 0px ${shadow}px ${2 * shadow}px 0px`,
401-
transform: `translate3d(${x}px, ${y}px, 0px) scale(${scale})`,
402-
WebkitTransform: `translate3d(${x}px, ${y}px, 0px) scale(${scale})`,
403-
MozTransform: `translate3d(${x}px, ${y}px, 0px) scale(${scale})`,
404-
MsTransform: `translate3d(${x}px, ${y}px, 0px) scale(${scale})`,
405-
zIndex: i === lastPressed ? 99 : i, // TODO: Add this.props.zIndex
406-
position: 'absolute',
407-
})}
414+
customStyle={customStyle}
408415
onMouseDown={onMouseDown}
409416
onTouchStart={onTouchStart}
410417
onResizeStart={onResizeStart}

0 commit comments

Comments
 (0)