Created
July 14, 2015 16:22
-
-
Save mattpodwysocki/9aeb5ce339cdb38a5dc2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const touchStart = Rx.Observable.fromEvent(window, 'touchstart').timestamp(); | |
const touchMove = Rx.Observable.fromEvent(window, 'touchmmove'); | |
const touchEnd = Rx.Observable.fromEvent(window, 'touchend').timestamp(); | |
const touchAndHold = touchStart | |
.flatMap(() => touchEnd.takeUntil(touchMove), (x, y) => { start: x.timestamp, end: y.timestamp }) | |
.filter(ts => (ts.end - ts.start) / 1000 > 2); | |
const subscription = touchAndHold.subscribe( | |
() => console.log('touch and hold!') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After a bit of experimentation, this isn't quite what I was looking for.
I want an observable that fires when the user is touching the screen and holds it there for a period of time. If he releases his finger, the observable shouldn't fire.
I ended up going with something like this:
This seems to work for my needs. Thanks again for your help!