Skip to content

Commit 2dfcc93

Browse files
author
Ives van Hoorne
committed
Fix detection of position change of preview
1 parent 8109077 commit 2dfcc93

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

packages/app/src/app/pages/Sandbox/Editor/Content/Preview/FlyingContainer.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class FlyingContainer extends React.Component<Props, State> {
4848
el: ?HTMLElement;
4949
initialWidth: ?number;
5050
initialHeight: ?number;
51+
lastX: ?number;
52+
lastY: ?number;
5153

5254
updateBounds = el => {
5355
if (el) {
@@ -63,14 +65,18 @@ class FlyingContainer extends React.Component<Props, State> {
6365
handleStartDrag = () => {
6466
this.setState({ dragging: true });
6567
this.setResizingStarted();
68+
69+
this.lastX = this.props.store.editor.previewWindow.x;
70+
this.lastY = this.props.store.editor.previewWindow.y;
6671
};
6772

6873
handleStopDrag = (e, data) => {
69-
const { x, y, deltaX, deltaY } = data;
70-
const delta = deltaX + deltaY;
74+
const { x, y } = data;
75+
const posChanged = x !== this.lastX || y !== this.lastY;
76+
7177
this.setState({ dragging: false });
7278

73-
this.setResizingStopped(delta);
79+
this.setResizingStopped(posChanged);
7480

7581
// We only set the bounds in the global store on stop, otherwise there are
7682
// other components constantly recalculating while dragging -> lag
@@ -81,10 +87,10 @@ class FlyingContainer extends React.Component<Props, State> {
8187
this.props.signals.editor.resizingStarted();
8288
};
8389

84-
setResizingStopped = (delta = -1) => {
90+
setResizingStopped = (posChanged = true) => {
8591
this.props.signals.editor.resizingStopped();
8692

87-
if (delta !== 0) {
93+
if (posChanged) {
8894
if (this.props.onPositionChange) {
8995
this.props.onPositionChange();
9096
}

0 commit comments

Comments
 (0)