Slide 1

Slide 1 text

STATE GESTURES THE OF Tilo Mitra I work on YUI & Pure @ Yahoo

Slide 2

Slide 2 text

Challenges of developing multi-device user experiences OR and what we’re doing about it.

Slide 3

Slide 3 text

Evolving World of Inputs

Slide 4

Slide 4 text

Let’s assume we want to “fast-click” on a button.

Slide 5

Slide 5 text

Mouse Keyboard

Slide 6

Slide 6 text

node.on('click', function (e) { ... });

Slide 7

Slide 7 text

Touch Accelerometer Gyroscope

Slide 8

Slide 8 text

if (window && ("ontouchstart" in window)) { node.on('touchend', DoSomething); } else { node.on('mouseup', DoSomething); }

Slide 9

Slide 9 text

Mouse + Touch

Slide 10

Slide 10 text

if (window && ("ontouchstart" in window)) { node.on('touchend', DoSomething); } else { node.on('mouseup', DoSomething); } This doesn’t get executed, so we can’t interact with mouse* events.

Slide 11

Slide 11 text

if (window && ("ontouchstart" in window)) { node.on(['touchend', 'mouseup'], function (e) { //so mouse* doesn’t fire if touchend fires e.preventDefault(); doSomething(e); }); }

Slide 12

Slide 12 text

if (window && ("ontouchstart" in window)) { node.on(['touchend', 'mouseup'], function (e) { //so mouse* doesn’t fire if touchend fires e.preventDefault(); doSomething(e); }); } else if (win && ("msPointerEnabled" in win.navigator)) { node.on('MSPointerUp', doSomething); }

Slide 13

Slide 13 text

if (window && ("ontouchstart" in window)) { node.on(['touchend', 'mouseup'], function (e) { //so mouse* doesn’t fire if touchend fires e.preventDefault(); doSomething(e); }); } else if (win && ("msPointerEnabled" in win.navigator)) { node.on('MSPointerUp', doSomething); } else { node.on('mouseup', doSomething); }

Slide 14

Slide 14 text

if (window && ("ontouchstart" in window)) { node.on(['touchend', 'mouseup'], function (e) { //so mouse* doesn’t fire if touchend fires e.preventDefault(); doSomething(e); }); } else if (win && ("msPointerEnabled" in win.navigator)) { node.on('MSPointerUp', doSomething); } else { node.on('mouseup', doSomething); } This gets complicated

Slide 15

Slide 15 text

This gets complicated What to do for more complex gestures? preventDefault() is heavy-handed

Slide 16

Slide 16 text

http://jsbin.com/IKegUbu/1 See what events your browser fires

Slide 17

Slide 17 text

Desktop Browser iOS Android IE10+ mousedown mousemove mouseup click touchstart touchmove touchend click touchstart mousedown touchmove mousemove touchend mouseup click MSPointerDown mousedown MSPointerMove mousemove MSPointerUp mouseup click

Slide 18

Slide 18 text

RWD CSS HTML /

Slide 19

Slide 19 text

RWD CSS HTML / JavaScript

Slide 20

Slide 20 text

re·spon·sive ADJECTIVE quick to react or respond

Slide 21

Slide 21 text

Decouple events from inputs

Slide 22

Slide 22 text

Decouple events from inputs finger mouse pen {{ some event }} Your App

Slide 23

Slide 23 text

Sound familiar? Basically what the Pointer Spec is about http://www.w3.org/Submission/pointer-events/

Slide 24

Slide 24 text

A pointer can be any point of contact on the screen made by a mouse cursor, pen, touch (including multi-touch), or other pointing input device. This model makes it easy to write sites and applications that work well no matter what hardware the user has.

Slide 25

Slide 25 text

Polyfill?

Slide 26

Slide 26 text

Polyfill? Why not improve gesturemove* events?

Slide 27

Slide 27 text

"gesturemovestart", "gesturemove", and "gesturemoveend" are events that serve as abstractions over mouse and touch events, forking internally based on the client device. From the Docs:

Slide 28

Slide 28 text

touchstart mousedown MSPointerDown gesturemovestart touchmove mousemove MSPointerMove touchend mouseup MSPointerUp gesturemove gesturemoveend

Slide 29

Slide 29 text

touchstart mousedown MSPointerDown gesturemovestart touchmove mousemove MSPointerMove touchend mouseup MSPointerUp gesturemove gesturemoveend Your App tap flick move/drag transforms

Slide 30

Slide 30 text

Improvements to event-move to make it work for mouse, touch and devices that support both Pull #1309 Code in Progress

Slide 31

Slide 31 text

Common fast-click use case, with e.preventDefault() support event-tap Available Today

Slide 32

Slide 32 text

EVENT UPDATES PAYLOAD STATUS STATUS tap Dual Listener Support, e.preventDefault() - Available Today Available Today flick flickup, flickdown flickleft, flickright direction velocity PULL #1323 PULL #1323 gesturemove* Dual Listener Support direction deltaX deltaY Pull #1309 See Demo move moveup, movedown moveleft, moveright, ability to lock axis direction deltaX deltaY See Demo See Demo NEW APIs

Slide 33

Slide 33 text

Demo CAROUSEL WITH NEW GESTURE EVENTS http://bit.ly/gesture-events

Slide 34

Slide 34 text

WHAT WE DO NOW 1. Set up some gesturemove* and flick listeners 2. Store the [x1,y1] of gesturemovestart 3. Compare [x1,y1] to [x2,y2] from gesturemove to determine direction + delta 4. Compare [x1,y1] to [x2,y2] from gesturemoveend to determine direction + delta 5. In callbacks, branch logic based on direction 6. Make sure that these do not get called twice in devices that support mouse and touch, but yet, also works with both.

Slide 35

Slide 35 text

WITH NEW APIs 1. Listen for move, flickleft, flickright, and gesturemoveend event 2. Inside move callback, get info with e.drag.direction and e.drag.deltaX 3. Transition to previous and next panels with flickleft and flickright 4. Inside gesturemoveend callback, get info with e.gesture.deltaX and e.gesture.dirX to decide whether or not to transition panels.

Slide 36

Slide 36 text

Going Forward

Slide 37

Slide 37 text

Pull #1309 gesturemove* improvements Pull #1323 flick* improvements tilomitra/yui3/gesture- integration Build of YUI with all of these modules Demo http://bit.ly/gesture-events

Slide 38

Slide 38 text

Check it out & Let us know what you think

Slide 39

Slide 39 text

THANKS @tilomitra GitHub & Twitter