Skip to content

Commit

Permalink
Detect mobile just once
Browse files Browse the repository at this point in the history
TODO: Check mobile once and add property to ARENA
  • Loading branch information
hi-liang committed Jun 7, 2023
1 parent d39414e commit 4a4c667
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/components/ar-hit-test-listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ AFRAME.registerComponent('ar-hit-test-listener', {
this.el.addEventListener('enter-vr', this.enterARHandler);
this.el.addEventListener('exit-vr', this.exitARHandler);
this.mouseCursor = document.getElementById('mouse-cursor');
this.isMobile = AFRAME.utils.device.isMobile();
},

remove: function() {
Expand All @@ -26,7 +27,7 @@ AFRAME.registerComponent('ar-hit-test-listener', {
if (this.el.is('ar-mode')) {
this.el.addEventListener('ar-hit-test-select-start', this.hitStartHandler);
this.el.addEventListener('ar-hit-test-select', this.hitEndHandler);
if (AFRAME.utils.device.isMobile()) {
if (this.isMobile) {
this.el.setAttribute('cursor', {rayOrigin: 'xrselect', fuse: false});
this.el.setAttribute('raycaster', {objects: '[click-listener],[click-listener-local]'});
this.mouseCursor.removeAttribute('cursor');
Expand All @@ -40,7 +41,7 @@ AFRAME.registerComponent('ar-hit-test-listener', {
exitARHandler: function() {
this.el.removeEventListener('ar-hit-test-select-start', this.hitStartHandler);
this.el.removeEventListener('ar-hit-test-select', this.hitEndHandler);
if (AFRAME.utils.device.isMobile()) {
if (this.isMobile) {
this.el.removeAttribute('cursor');
this.el.removeAttribute('raycaster');
this.mouseCursor.setAttribute('cursor', {rayOrigin: 'mouse'});
Expand Down

0 comments on commit 4a4c667

Please sign in to comment.