Skip to content

Conversation

@jsimonson2013
Copy link
Contributor

Description:

While working on an AR.js + A-Frame app that allows users to draw/paint in AR, I wanted users to be able to use touch events to draw on a mobile device and use device orientation to change camera orientation. Touch events are included in look-controls by default, with no disable action allowed. Using touchmove events to draw resulted in drawing across the scene in a reverse pan because of the way that touchmove is coupled with look-controls. In magic window mode, there could be many applications of touch events that would not want to also change device orientation.

Changes proposed:

  • Add property to look-controls schema
  • Check property for true before binding, adding, and removing TouchEvent-related functions

Copy link
Member

@donmccurdy donmccurdy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'm happy with adding this option to look-controls, with a few suggested changes.

this.onTouchStart = bind(this.onTouchStart, this);
this.onTouchMove = bind(this.onTouchMove, this);
this.onTouchEnd = bind(this.onTouchEnd, this);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This event binding should happen regardless of data.touchEnabled, because touch events might be enabled or disabled at a later time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, This condition is not necessary. We should bind the methods regardless of the flag

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in commit 1d6930b

canvasEl.removeEventListener('touchstart', this.onTouchStart);
canvasEl.removeEventListener('touchmove', this.onTouchMove);
canvasEl.removeEventListener('touchend', this.onTouchEnd);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be better to return early from these event listeners when touch is disabled, rather than conditionally binding or not. Otherwise, (1) setAttribute('look-controls', {touchEnabled: false}) will have no effect, and (2) calls to pause() after that will fail to remove the old touch listeners.

So instead:

onTouchStart: function () {
  if (!this.data.touchEnabled) { return; }

  // ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in commit 1d6930b


<ul class="links">
<li><a href="boilerplate/hello-world/">Hello World</a></li>
<li><a href="boilerplate/hello-world-touch-disabled/">Hello World Touch Disabled</a></li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not necessary to add an example for this, but could you instead add an entry in the look-controls documentation for the new option?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, It seems that just a flag does not justify a whole example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in commit 1d6930b

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we need an example specific for just one flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in commit 1d6930b

canvasEl.addEventListener('touchstart', this.onTouchStart);
window.addEventListener('touchmove', this.onTouchMove);
window.addEventListener('touchend', this.onTouchEnd);
if (this.data.touchEnabled) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also have to handle the dynamic case when the flag changes at runtime. We probably need a method updateTouchListeners that contains this logic and its called from here and the update method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the enabled flag is updated at runtime, a grab cursor is shown or hidden accordingly. I'm not sure what would need to be updated, other than the behavior that the flag controls (updated in commit 1d6930b). Would the behavior change accordingly when the flag is set at runtime?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is taken care of, given the last set of changes, yes?

@jsimonson2013
Copy link
Contributor Author

jsimonson2013 commented Aug 29, 2017

Thanks for the feedback @donmccurdy and @dmarcos . I will implement those suggested changes soon.

…instead of conditionally managing event handlers.
@dmarcos
Copy link
Member

dmarcos commented Sep 1, 2017

Thanks!

@dmarcos dmarcos merged commit 790a3ae into aframevr:master Sep 1, 2017
@jsimonson2013 jsimonson2013 deleted the workbranch branch September 1, 2017 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants