Browse Source

Merge pull request #5679 from sebavan/master

Auto update touch action
sebavan 6 years ago
parent
commit
5ba396058e
2 changed files with 20 additions and 0 deletions
  1. 1 0
      dist/preview release/what's new.md
  2. 19 0
      src/Engine/babylon.engine.ts

+ 1 - 0
dist/preview release/what's new.md

@@ -153,6 +153,7 @@
 - Fix a bug when a call to `updateIndices` leads to changing the size of the index buffer by recreating the subMeshes in that case ([barroij](https://github.com/barroij))
 - Add option to disable gazeTracker color changes in vrExperienceHelper ([TrevorDev](https://github.com/TrevorDev))
 - PointerDragBehavior validateDrag predicate to stop dragging to specific points ([TrevorDev](https://github.com/TrevorDev))
+- Auto Update Touch Action [#5674](https://github.com/BabylonJS/Babylon.js/issues/5674)([Sebavan](https://github.com/Sebavan))
 
 ### Viewer
 

+ 19 - 0
src/Engine/babylon.engine.ts

@@ -199,6 +199,11 @@ module BABYLON {
          * If this event happens when this parameter is true, you will have to reload the page to restore rendering
          */
         doNotHandleContextLost?: boolean;
+        /**
+         * Defines that engine should ignore modifying touch action attribute and style
+         * If not handle, you might need to set it up on your side for expected touch devices behavior.
+         */
+        doNotHandleTouchAction?: boolean;
     }
 
     /**
@@ -1147,6 +1152,10 @@ module BABYLON {
                     canvas.addEventListener("webglcontextlost", this._onContextLost, false);
                     canvas.addEventListener("webglcontextrestored", this._onContextRestored, false);
                 }
+
+                if (!options.doNotHandleTouchAction) {
+                    this._disableTouchAction();
+                }
             } else {
                 this._gl = <WebGLRenderingContext>canvasOrContext;
                 this._renderingCanvas = this._gl.canvas;
@@ -1260,6 +1269,16 @@ module BABYLON {
             this.enableOfflineSupport = Engine.OfflineProviderFactory !== undefined;
         }
 
+        private _disableTouchAction(): void {
+            if (!this._renderingCanvas) {
+                return;
+            }
+
+            this._renderingCanvas.setAttribute("touch-action", "none");
+            this._renderingCanvas.style.touchAction = "none";
+            this._renderingCanvas.style.msTouchAction = "none";
+        }
+
         private _rebuildInternalTextures(): void {
             let currentState = this._internalTexturesCache.slice(); // Do a copy because the rebuild will add proxies