mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 03:32:21 +08:00
30 lines
814 B
TypeScript
30 lines
814 B
TypeScript
import {SlideEdgeGesture} from 'ionic/gestures/slide-edge-gesture';
|
|
|
|
|
|
export class SwipeBackGesture extends SlideEdgeGesture {
|
|
|
|
constructor(element: Element, opts: Object = {}, viewCtrl) {
|
|
super(element, opts);
|
|
// Can check corners through use of eg 'left top'
|
|
this.edges = opts.edge.split(' ');
|
|
this.threshold = opts.threshold;
|
|
this.viewCtrl = viewCtrl;
|
|
}
|
|
|
|
onSlideStart() {
|
|
this.viewCtrl.swipeBackStart();
|
|
}
|
|
|
|
onSlide(slide, ev) {
|
|
this.viewCtrl.swipeBackProgress(slide.distance / slide.max);
|
|
}
|
|
|
|
onSlideEnd(slide, ev) {
|
|
let shouldComplete = (Math.abs(ev.velocityX) > 0.2 || Math.abs(slide.delta) > Math.abs(slide.max) * 0.5);
|
|
|
|
// TODO: calculate a better playback rate depending on velocity and distance
|
|
this.viewCtrl.swipeBackFinish(shouldComplete, 1);
|
|
}
|
|
|
|
}
|