From 4a4c667d57a06d09686ca31e16048c2a7adf29be Mon Sep 17 00:00:00 2001 From: Ivan Liang Date: Wed, 7 Jun 2023 14:32:54 -0400 Subject: [PATCH] Detect mobile just once TODO: Check mobile once and add property to ARENA --- src/components/ar-hit-test-listener.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/ar-hit-test-listener.js b/src/components/ar-hit-test-listener.js index edb413ac7..ac6420c42 100644 --- a/src/components/ar-hit-test-listener.js +++ b/src/components/ar-hit-test-listener.js @@ -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() { @@ -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'); @@ -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'});