Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to detect "cross slide" gesture when element is scrollable
    text
    copied!<p>I'm currently trying to detect a cross-slide gesture on a <code>div</code> using the <code>Windows.UI.Input.GestureRecognizer</code> class.</p> <p>I have been able to successfully achieve the detection of this gesture <em>except</em> when the element is in a scrollable region.</p> <p>Specifically, when it <em>is</em> in a scrollable region, I receive an <code>MSPointerCancel</code> event almost immediately after the <code>MSPointerDown</code> event -- if I move the touch interaction slowly, I do see <em>some</em> <code>MSPointerMove</code> events, but then it goes off and cancels it.</p> <p>Digging into the <code>WinJS.UI.ListView</code> implementation, I'm pretty much doing the same things. That behavior <em>does</em> work, so I don't believe this is an issue with drivers or the simulator.</p> <p>To see this code cross sliding, change the CSS as follows:</p> <p><code>.container</code>: Change <code>width: 3000px</code> to <code>width: 300px</code></p> <p><strong>Sample Code</strong></p> <p>This code can be tested by creating a Blank JavaScript application in Visual Studio, and pasting the code in where discussed below.</p> <p><em>JavaScript, end of Default.js</em></p> <pre><code>WinJS.Namespace.define("Sample", { Swiper: WinJS.Class.define(function (el, options) { this.element = el; WinJS.UI.setOptions(options); this.mouseUp = this.mouseUp.bind(this); this.keyPress = this.keyPress.bind(this); //el.addEventListener("mouseup", this.mouseUp, true); el.addEventListener("keypress", this.keyPress); // Gesture events this.pointerDown = this.pointerDown.bind(this); this.pointerMove = this.pointerMove.bind(this); this.pointerUp = this.pointerUp.bind(this); this.pointerCancel = this.pointerCancel.bind(this); el.addEventListener("MSPointerDown", this.pointerDown, true); el.addEventListener("MSPointerMove", this.pointerMove, true); el.addEventListener("MSPointerUp", this.pointerUp, true); el.addEventListener("MSPointerCancel", this.pointerCancel, true); }, { element: null, _recognizer: null, wasSelected: false, currentTarget: null, pointer: null, mouseUp: function (e) { if(!e) { return; } if(e.button !== Sample.Swiper.RIGHT_MOUSE) { return; } if (!WinJS.Utilities.hasClass(e.srcElement, "swipeable")) { return; } this._toggleSelection(e.srcElement); }, keyPress: function (e) { if (!e) { return; } if (e.keyCode !== WinJS.Utilities.Key.space) { return; } if (!WinJS.Utilities.hasClass(e.srcElement, "swipeable")) { return; } this._toggleSelection(e.srcElement); }, pointerDown: function (e) { console.log("Pointer: Down"); if (!WinJS.Utilities.hasClass(e.srcElement, "swipeable")) { return; } var p = Windows.UI.Input.PointerPoint.getCurrentPoint(e.pointerId); var touch = (e.pointerType === Sample.Swiper.TOUCH); var pointerProperties = p.properties; this.pointer = e.pointerId; if (!touch) { this.mouseUp(e); return; } this.currentTarget = e.srcElement; window.proxy.msSetPointerCapture(p.pointerId); this._getRecognizer().processDownEvent(p); //e.stopImmediatePropagation(); e.preventDefault(); }, pointerMove: function (e) { if (e.pointerId !== this.pointer) { return; } console.log("Pointer: Move"); var ips = Windows.UI.Input.PointerPoint.getIntermediatePoints(e.pointerId); this._getRecognizer().processMoveEvents(ips); //e.stopImmediatePropagation(); }, pointerUp: function (e) { if (e.pointerId !== this.pointer) { return; } console.log("Pointer: Up"); var p = Windows.UI.Input.PointerPoint.getCurrentPoint(e.pointerId); this._getRecognizer().processUpEvent(p); //e.stopImmediatePropagation(); }, pointerCancel: function (e) { if (e.pointerId !== this.pointer) { return; } console.log("Pointer: Canceled"); this._getRecognizer().completeGesture(); e.stopImmediatePropagation(); }, _toggleSelection: function (el) { WinJS.Utilities.toggleClass(el, "selected"); }, _getRecognizer: function () { if (this._recognizer) { return this._recognizer; } var gr = new Windows.UI.Input.GestureRecognizer(); gr.showGestureFeedback = false; var thresholds = gr.crossSlideThresholds; thresholds.selectionStart = WinJS.UI._VERTICAL_SWIPE_SELECTION_THRESHOLD; thresholds.speedBumpStart = WinJS.UI._VERTICAL_SWIPE_SPEED_BUMP_START; thresholds.speedBumpEnd = WinJS.UI._VERTICAL_SWIPE_SPEED_BUMP_END; thresholds.rearrangeStart = null; gr.crossSlideThresholds = thresholds; gr.crossSlideHorizontally = false; var settings = Windows.UI.Input.GestureSettings; gr.gestureSettings = settings.crossSlide; gr.addEventListener("crosssliding", function (e) { var el = this.currentTarget || document.createElement("div"); console.log("CrossSlide State: " + e.crossSlidingState); switch (e.crossSlidingState) { case Windows.UI.Input.CrossSlidingState.selecting: this.wasSelected = true; break; case Windows.UI.Input.CrossSlidingState.completed: if (this.wasSelected) { this._toggleSelection(this.currentTarget); } this.wasSelected = false; this.currentTarget = false; break; default: this.wasSelected = false; break; } }.bind(this)); gr.addEventListener("manipulationstarted", function (e) { debugger; }); this._recognizer = gr; return gr; } }, { RIGHT_MOUSE: 2, TOUCH: 2, }), }); </code></pre> <p><em>HTML, replace body in default.html</em></p> <pre><code>&lt;body&gt; &lt;div class="scroller" data-win-control="Sample.Swiper"&gt; &lt;div id="proxy"&gt;&lt;/div&gt; &lt;div class="container"&gt; &lt;div class="item swipeable" tabindex="0"&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; </code></pre> <p><em>CSS, add to default.css</em></p> <pre><code>.scroller { width: 100vw; height: 100vh; overflow-x: auto; -ms-touch-action: auto; } .container { width: 3000px; height: 100vh; display: -ms-grid; -ms-grid-columns: 1fr 100px 1fr; -ms-grid-rows: 1fr 100px 1fr; } .item { background-color: red; -ms-grid-column: 2; -ms-grid-row: 2; } .selected { outline-color: white; outline-style: solid; outline-width: 3px; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload