@@ -44,6 +44,7 @@ export default class ThreeSixtyScene extends React.Component {
44
44
45
45
this . handleFirstRender = this . handleFirstRender . bind ( this ) ;
46
46
this . handleSceneMoveStart = this . handleSceneMoveStart . bind ( this ) ;
47
+ this . handleSceneMove = this . handleSceneMove . bind ( this ) ;
47
48
this . handleSceneMoveStop = this . handleSceneMoveStop . bind ( this ) ;
48
49
49
50
this . terminateAffordance = this . terminateAffordance . bind ( this ) ;
@@ -242,6 +243,23 @@ export default class ThreeSixtyScene extends React.Component {
242
243
}
243
244
}
244
245
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
+
245
263
/**
246
264
* Handle dragging scene ended.
247
265
* @param {H5P.Event } event Event.
@@ -250,6 +268,11 @@ export default class ThreeSixtyScene extends React.Component {
250
268
if ( this . context . extras . isEditor ) {
251
269
this . cancelPointerLock ( ) ;
252
270
}
271
+
272
+ window . requestAnimationFrame ( ( ) => {
273
+ this . setState ( { sceneIsDragging : false } ) ;
274
+ } ) ;
275
+
253
276
this . context . trigger ( 'movestop' , event . data ) ;
254
277
}
255
278
@@ -264,6 +287,7 @@ export default class ThreeSixtyScene extends React.Component {
264
287
// Remove handlers.
265
288
this . props . threeSixty . stopRendering ( ) ;
266
289
this . props . threeSixty . off ( 'movestart' , this . handleSceneMoveStart ) ;
290
+ this . props . threeSixty . off ( 'move' , this . handleSceneMove ) ;
267
291
this . props . threeSixty . off ( 'movestop' , this . handleSceneMoveStop ) ;
268
292
this . props . threeSixty . off ( 'firstrender' , this . handleFirstRender ) ;
269
293
}
@@ -315,6 +339,7 @@ export default class ThreeSixtyScene extends React.Component {
315
339
threeSixty . update ( ) ;
316
340
317
341
threeSixty . on ( 'movestart' , this . handleSceneMoveStart ) ;
342
+ threeSixty . on ( 'move' , this . handleSceneMove ) ;
318
343
threeSixty . on ( 'movestop' , this . handleSceneMoveStop ) ;
319
344
320
345
// Add buttons to scene
@@ -518,6 +543,7 @@ export default class ThreeSixtyScene extends React.Component {
518
543
:
519
544
< NavigationButton
520
545
key = { key }
546
+ sceneIsDragging = { this . state . sceneIsDragging }
521
547
staticScene = { false }
522
548
leftPosition = { null }
523
549
topPosition = { null }
@@ -590,17 +616,6 @@ export default class ThreeSixtyScene extends React.Component {
590
616
* @param {number } index Index of interaction linked to navigation button.
591
617
*/
592
618
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
-
604
619
this . props . showInteraction . bind ( this ) ( index ) ;
605
620
}
606
621
@@ -657,6 +672,7 @@ export default class ThreeSixtyScene extends React.Component {
657
672
// No longer active, indicate that scene must be updated
658
673
this . props . threeSixty . stopRendering ( ) ;
659
674
this . props . threeSixty . off ( 'movestart' , this . handleSceneMoveStart ) ;
675
+ this . props . threeSixty . off ( 'move' , this . handleSceneMove ) ;
660
676
this . props . threeSixty . off ( 'movestop' , this . handleSceneMoveStop ) ;
661
677
this . props . threeSixty . off ( 'firstrender' , this . handleFirstRender ) ;
662
678
this . setState ( {
0 commit comments