Skip to content

Commit 9bf9091

Browse files
committed
Fix dragging detection
1 parent 38baad6 commit 9bf9091

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

scripts/components/Interactions/NavigationButton.js

+4
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ export default class NavigationButton extends React.Component {
286286
* Handle click.
287287
*/
288288
onClick() {
289+
if (this.props.sceneIsDragging) {
290+
return;
291+
}
292+
289293
if (this.props.forceClickHandler || !this.context.extras.isEditor) {
290294
this.props.clickHandler();
291295

scripts/components/Scene/SceneTypes/ThreeSixtyScene.js

+27-11
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export default class ThreeSixtyScene extends React.Component {
4444

4545
this.handleFirstRender = this.handleFirstRender.bind(this);
4646
this.handleSceneMoveStart = this.handleSceneMoveStart.bind(this);
47+
this.handleSceneMove = this.handleSceneMove.bind(this);
4748
this.handleSceneMoveStop = this.handleSceneMoveStop.bind(this);
4849

4950
this.terminateAffordance = this.terminateAffordance.bind(this);
@@ -242,6 +243,23 @@ export default class ThreeSixtyScene extends React.Component {
242243
}
243244
}
244245

246+
/**
247+
* Handle dragging scene ongoing.
248+
*/
249+
handleSceneMove() {
250+
if (this.context.extras.isEditor) {
251+
return;
252+
}
253+
254+
// Consider to be dragging after moving beyond maximum slack.
255+
const endPosition = this.props.threeSixty.getCurrentPosition();
256+
const sceneIsDragging =
257+
Math.abs(endPosition.yaw - this.startPosition?.yaw ?? 0) > ThreeSixtyScene.MAX_YAW_DELTA ||
258+
Math.abs(endPosition.pitch - this.startPosition?.pitch ?? 0) > ThreeSixtyScene.MAX_PITCH_DELTA;
259+
260+
this.setState({ sceneIsDragging: sceneIsDragging });
261+
}
262+
245263
/**
246264
* Handle dragging scene ended.
247265
* @param {H5P.Event} event Event.
@@ -250,6 +268,11 @@ export default class ThreeSixtyScene extends React.Component {
250268
if (this.context.extras.isEditor) {
251269
this.cancelPointerLock();
252270
}
271+
272+
window.requestAnimationFrame(() => {
273+
this.setState({ sceneIsDragging: false });
274+
});
275+
253276
this.context.trigger('movestop', event.data);
254277
}
255278

@@ -264,6 +287,7 @@ export default class ThreeSixtyScene extends React.Component {
264287
// Remove handlers.
265288
this.props.threeSixty.stopRendering();
266289
this.props.threeSixty.off('movestart', this.handleSceneMoveStart);
290+
this.props.threeSixty.off('move', this.handleSceneMove);
267291
this.props.threeSixty.off('movestop', this.handleSceneMoveStop);
268292
this.props.threeSixty.off('firstrender', this.handleFirstRender);
269293
}
@@ -315,6 +339,7 @@ export default class ThreeSixtyScene extends React.Component {
315339
threeSixty.update();
316340

317341
threeSixty.on('movestart', this.handleSceneMoveStart);
342+
threeSixty.on('move', this.handleSceneMove);
318343
threeSixty.on('movestop', this.handleSceneMoveStop);
319344

320345
// Add buttons to scene
@@ -518,6 +543,7 @@ export default class ThreeSixtyScene extends React.Component {
518543
:
519544
<NavigationButton
520545
key={key}
546+
sceneIsDragging={this.state.sceneIsDragging}
521547
staticScene={false}
522548
leftPosition={null}
523549
topPosition={null}
@@ -590,17 +616,6 @@ export default class ThreeSixtyScene extends React.Component {
590616
* @param {number} index Index of interaction linked to navigation button.
591617
*/
592618
handleNavButtonClick(index) {
593-
// Prevent click if user also dragged button beyond maximum slack.
594-
const endPosition = this.props.threeSixty.getCurrentPosition();
595-
if (
596-
Math.abs(endPosition.yaw - this.startPosition?.yaw) >
597-
ThreeSixtyScene.MAX_YAW_DELTA ||
598-
Math.abs(endPosition.pitch - this.startPosition?.pitch) >
599-
ThreeSixtyScene.MAX_PITCH_DELTA
600-
) {
601-
return; // Dragged button too much for click
602-
}
603-
604619
this.props.showInteraction.bind(this)(index);
605620
}
606621

@@ -657,6 +672,7 @@ export default class ThreeSixtyScene extends React.Component {
657672
// No longer active, indicate that scene must be updated
658673
this.props.threeSixty.stopRendering();
659674
this.props.threeSixty.off('movestart', this.handleSceneMoveStart);
675+
this.props.threeSixty.off('move', this.handleSceneMove);
660676
this.props.threeSixty.off('movestop', this.handleSceneMoveStop);
661677
this.props.threeSixty.off('firstrender', this.handleFirstRender);
662678
this.setState({

0 commit comments

Comments
 (0)