mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
swipe back and the seven dwarfs
This commit is contained in:
@@ -21,47 +21,51 @@ export class SwipeHandle {
|
||||
gesture.on('panleft', onDragHorizontal);
|
||||
gesture.on('panright', onDragHorizontal);
|
||||
|
||||
let navWidth = 0;
|
||||
let startX = null;
|
||||
let swipeableAreaWidth = null;
|
||||
|
||||
function onDragEnd(ev) {
|
||||
// TODO: POLISH THESE NUMBERS WITH GOOD MATHIFICATION
|
||||
|
||||
let progress = ev.gesture.center.x / navWidth;
|
||||
let progress = (ev.gesture.center.x - startX) / swipeableAreaWidth;
|
||||
let completeSwipeBack = (progress > 0.5);
|
||||
let playbackRate = 4;
|
||||
|
||||
if (completeSwipeBack) {
|
||||
// complete swipe back
|
||||
if (progress > 0.7) {
|
||||
playbackRate = 3;
|
||||
if (progress > 0.9) {
|
||||
playbackRate = 1;
|
||||
} else if (progress > 0.8) {
|
||||
playbackRate = 2;
|
||||
} else if (progress > 0.9) {
|
||||
playbackRate = 1;
|
||||
} else if (progress > 0.7) {
|
||||
playbackRate = 3;
|
||||
}
|
||||
|
||||
} else {
|
||||
// cancel swipe back
|
||||
if (progress < 0.3) {
|
||||
playbackRate = 3;
|
||||
if (progress < 0.1) {
|
||||
playbackRate = 1;
|
||||
} else if (progress < 0.2) {
|
||||
playbackRate = 2;
|
||||
} else if (progress < 0.1) {
|
||||
playbackRate = 1;
|
||||
} else if (progress < 0.3) {
|
||||
playbackRate = 3;
|
||||
}
|
||||
}
|
||||
|
||||
nav.swipeBackEnd(completeSwipeBack, progress, playbackRate);
|
||||
navWidth = 0;
|
||||
|
||||
startX = null;
|
||||
}
|
||||
|
||||
function onDragHorizontal(ev) {
|
||||
if (navWidth === 0) {
|
||||
navWidth = nav.width();
|
||||
if (startX === null) {
|
||||
startX = ev.gesture.center.x;
|
||||
swipeableAreaWidth = nav.width() - startX;
|
||||
|
||||
nav.swipeBackStart();
|
||||
}
|
||||
|
||||
nav.swipeBackProgress( ev.gesture.center.x / navWidth );
|
||||
nav.swipeBackProgress( (ev.gesture.center.x - startX) / swipeableAreaWidth );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user