mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 03:32:21 +08:00
a swipe back named desire
This commit is contained in:
45
ionic/components/content/swipe-handle.js
Normal file
45
ionic/components/content/swipe-handle.js
Normal file
@ -0,0 +1,45 @@
|
||||
import {ElementRef} from 'angular2/angular2'
|
||||
import {Ancestor} from 'angular2/src/core/annotations_impl/visibility';
|
||||
import {Directive} from 'angular2/src/core/annotations_impl/annotations';
|
||||
|
||||
import {Gesture} from 'ionic/gestures/gesture';
|
||||
import {NavItem} from '../nav/nav-item';
|
||||
|
||||
|
||||
@Directive({
|
||||
selector: 'swipe-handle'
|
||||
})
|
||||
export class SwipeHandle {
|
||||
constructor(@Ancestor() navItem: NavItem, elementRef: ElementRef) {
|
||||
let nav = navItem.nav;
|
||||
|
||||
let gesture = new Gesture(elementRef.domElement);
|
||||
|
||||
gesture.listen();
|
||||
|
||||
gesture.on('panend', onDragEnd);
|
||||
gesture.on('panleft', onDragHorizontal);
|
||||
gesture.on('panright', onDragHorizontal);
|
||||
|
||||
let navWidth = 0;
|
||||
|
||||
function onDragEnd(ev) {
|
||||
let completeSwipeBack = (ev.gesture.center.x / navWidth) > 0.5;
|
||||
|
||||
nav.swipeBackEnd(completeSwipeBack);
|
||||
|
||||
navWidth = 0;
|
||||
}
|
||||
|
||||
function onDragHorizontal(ev) {
|
||||
if (navWidth === 0) {
|
||||
navWidth = nav.width();
|
||||
nav.swipeBackStart();
|
||||
}
|
||||
|
||||
nav.swipeBackProgress( ev.gesture.center.x / navWidth );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user