mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
@ -1,4 +1,4 @@
|
|||||||
import {Component, Directive, ElementRef, NgIf, Host, Optional, Renderer} from 'angular2/angular2';
|
import {Component, Directive, ElementRef, NgIf, Host, Optional, Renderer, NgZone} from 'angular2/angular2';
|
||||||
|
|
||||||
import {Gesture} from 'ionic/gestures/gesture';
|
import {Gesture} from 'ionic/gestures/gesture';
|
||||||
import {DragGesture} from 'ionic/gestures/drag-gesture';
|
import {DragGesture} from 'ionic/gestures/drag-gesture';
|
||||||
@ -48,7 +48,8 @@ export class ItemSliding {
|
|||||||
* TODO
|
* TODO
|
||||||
* @param {ElementRef} elementRef A reference to the component's DOM element.
|
* @param {ElementRef} elementRef A reference to the component's DOM element.
|
||||||
*/
|
*/
|
||||||
constructor(elementRef: ElementRef, renderer: Renderer, @Optional() @Host() list: List) {
|
constructor(elementRef: ElementRef, renderer: Renderer, @Optional() @Host() list: List, zone: NgZone) {
|
||||||
|
this._zone = zone;
|
||||||
renderer.setElementClass(elementRef, 'item', true);
|
renderer.setElementClass(elementRef, 'item', true);
|
||||||
|
|
||||||
this._isOpen = false;
|
this._isOpen = false;
|
||||||
@ -58,32 +59,25 @@ export class ItemSliding {
|
|||||||
|
|
||||||
this.list = list;
|
this.list = list;
|
||||||
|
|
||||||
this.ele = elementRef.nativeElement;
|
this.elementRef = elementRef;
|
||||||
this.swipeButtons = {};
|
this.swipeButtons = {};
|
||||||
this.optionButtons = {};
|
this.optionButtons = {};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onInit() {
|
onInit() {
|
||||||
this._initSliding();
|
let ele = this.elementRef.nativeElement;
|
||||||
}
|
this.itemSlidingContent = ele.querySelector('ion-item-sliding-content');
|
||||||
|
this.itemOptions = ele.querySelector('ion-item-options');
|
||||||
_initSliding() {
|
|
||||||
var itemSlidingContent = this.ele.querySelector('ion-item-sliding-content');
|
|
||||||
var itemOptionsContent = this.ele.querySelector('ion-item-options');
|
|
||||||
|
|
||||||
console.log('List width', this.list.width());
|
|
||||||
|
|
||||||
this.itemSlidingContent = itemSlidingContent;
|
|
||||||
this.itemOptions = itemOptionsContent;
|
|
||||||
|
|
||||||
this.itemWidth = this.list.width();
|
|
||||||
|
|
||||||
this.openAmount = 0;
|
this.openAmount = 0;
|
||||||
|
this._zone.runOutsideAngular(() => {
|
||||||
this.gesture = new ItemSlideGesture(this, itemSlidingContent);
|
this.gesture = new ItemSlideGesture(this, this.itemSlidingContent, this._zone);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onDestroy() {
|
||||||
|
this.gesture && this.gesture.unlisten();
|
||||||
|
this.itemSlidingContent = this.itemOptionsContent = null;
|
||||||
|
}
|
||||||
|
|
||||||
close(andStopDrag) {
|
close(andStopDrag) {
|
||||||
this.openAmount = 0;
|
this.openAmount = 0;
|
||||||
@ -91,93 +85,97 @@ export class ItemSliding {
|
|||||||
// Enable it once, it'll get disabled on the next drag
|
// Enable it once, it'll get disabled on the next drag
|
||||||
raf(() => {
|
raf(() => {
|
||||||
this.enableAnimation();
|
this.enableAnimation();
|
||||||
if(this.itemSlidingContent) {
|
if (this.itemSlidingContent) {
|
||||||
this.itemSlidingContent.style[CSS.transform] = 'translateX(0)';
|
this.itemSlidingContent.style[CSS.transform] = 'translateX(0)';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
open(amt) {
|
open(amt) {
|
||||||
let el = this.itemSlidingContent;
|
let el = this.itemSlidingContent;
|
||||||
this.openAmount = amt || 0;
|
this.openAmount = amt || 0;
|
||||||
|
|
||||||
if(this.list) {
|
if (this.list) {
|
||||||
this.list.setOpenItem(this);
|
this.list.setOpenItem(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(amt === '') {
|
if (amt === '') {
|
||||||
el.style[CSS.transform] = '';
|
el.style[CSS.transform] = '';
|
||||||
} else {
|
} else {
|
||||||
el.style[CSS.transform] = 'translateX(' + -amt + 'px)';
|
el.style[CSS.transform] = 'translateX(' + -amt + 'px)';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isOpen() {
|
isOpen() {
|
||||||
return this.openAmount > 0;
|
return this.openAmount > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
getOpenAmt() {
|
getOpenAmt() {
|
||||||
return this.openAmount;
|
return this.openAmount;
|
||||||
}
|
}
|
||||||
getItemWidth() {
|
|
||||||
return this.itemWidth;
|
|
||||||
}
|
|
||||||
disableAnimation() {
|
disableAnimation() {
|
||||||
this.itemSlidingContent.style[CSS.transition] = 'none';
|
this.itemSlidingContent.style[CSS.transition] = 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
enableAnimation() {
|
enableAnimation() {
|
||||||
// Clear the explicit transition, allow for CSS one to take over
|
// Clear the explicit transition, allow for CSS one to take over
|
||||||
this.itemSlidingContent.style[CSS.transition] = '';
|
this.itemSlidingContent.style[CSS.transition] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User did a touchstart
|
* User did a touchstart
|
||||||
*/
|
*/
|
||||||
didTouch() {
|
didTouch() {
|
||||||
if(this.isOpen()) {
|
if (this.isOpen()) {
|
||||||
this.close();
|
this.close();
|
||||||
this.didClose = true;
|
this.didClose = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
let openItem = this.list.getOpenItem();
|
let openItem = this.list.getOpenItem();
|
||||||
if(openItem && openItem !== this) {
|
if (openItem && openItem !== this) {
|
||||||
this.didClose = true;
|
this.didClose = true;
|
||||||
}
|
}
|
||||||
if(this.list) {
|
if (this.list) {
|
||||||
this.list.closeOpenItem();
|
this.list.closeOpenItem();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ItemSlideGesture extends DragGesture {
|
class ItemSlideGesture extends DragGesture {
|
||||||
constructor(item: ItemSliding, el: Element) {
|
constructor(item: ItemSliding, el: Element, zone) {
|
||||||
|
|
||||||
super(el, {
|
super(el, {
|
||||||
direction: 'x',
|
direction: 'x',
|
||||||
threshold: el.offsetWidth
|
threshold: el.offsetWidth
|
||||||
});
|
});
|
||||||
|
|
||||||
this.el = el;
|
|
||||||
this.item = item;
|
this.item = item;
|
||||||
this.canDrag = true;
|
this.canDrag = true;
|
||||||
this.listen();
|
this.listen();
|
||||||
|
|
||||||
this.el.addEventListener('touchstart', (e) => {
|
zone.runOutsideAngular(() => {
|
||||||
|
el.addEventListener('touchstart', (e) => {
|
||||||
this.item.didTouch();
|
this.item.didTouch();
|
||||||
raf(() => {
|
raf(() => {
|
||||||
this.item.itemOptionsWidth = this.item.itemOptions && this.item.itemOptions.offsetWidth || 0;
|
this.item.itemOptionsWidth = this.item.itemOptions && this.item.itemOptions.offsetWidth || 0;
|
||||||
})
|
})
|
||||||
})
|
});
|
||||||
|
|
||||||
this.el.addEventListener('touchend', (e) => {
|
el.addEventListener('touchend', (e) => {
|
||||||
this.item.didClose = false;
|
this.item.didClose = false;
|
||||||
});
|
});
|
||||||
this.el.addEventListener('touchcancel', (e) => {
|
|
||||||
|
el.addEventListener('touchcancel', (e) => {
|
||||||
this.item.didClose = false;
|
this.item.didClose = false;
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onDragStart(ev) {
|
onDragStart(ev) {
|
||||||
if(this.item.didClose) { return; }
|
if (this.item.didClose) { return; }
|
||||||
|
|
||||||
if(!this.item.itemOptionsWidth) { return; }
|
if (!this.item.itemOptionsWidth) { return; }
|
||||||
|
|
||||||
this.slide = {};
|
this.slide = {};
|
||||||
|
|
||||||
@ -198,7 +196,7 @@ class ItemSlideGesture extends DragGesture {
|
|||||||
|
|
||||||
let buttonsWidth = this.item.itemOptionsWidth;
|
let buttonsWidth = this.item.itemOptionsWidth;
|
||||||
|
|
||||||
if(newX > this.item.itemOptionsWidth) {
|
if (newX > this.item.itemOptionsWidth) {
|
||||||
// Calculate the new X position, capped at the top of the buttons
|
// Calculate the new X position, capped at the top of the buttons
|
||||||
newX = -Math.min(-buttonsWidth, -buttonsWidth + (((this.slide.delta + buttonsWidth) * 0.4)));
|
newX = -Math.min(-buttonsWidth, -buttonsWidth + (((this.slide.delta + buttonsWidth) * 0.4)));
|
||||||
}
|
}
|
||||||
@ -238,6 +236,7 @@ class ItemSlideGesture extends DragGesture {
|
|||||||
this.hideButtonsTimeout = setTimeout(() => {
|
this.hideButtonsTimeout = setTimeout(() => {
|
||||||
buttons && buttons.classList.add('invisible');
|
buttons && buttons.classList.add('invisible');
|
||||||
}, 250);
|
}, 250);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
this.item.open(restingPoint);
|
this.item.open(restingPoint);
|
||||||
}
|
}
|
||||||
|
@ -10,4 +10,10 @@ class E2EApp {
|
|||||||
this.shouldShow = true;
|
this.shouldShow = true;
|
||||||
}, 5000);
|
}, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getItems() {
|
||||||
|
console.log('getItems');
|
||||||
|
return [1,2,3,4];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -43,4 +43,12 @@
|
|||||||
<button primary>Archive</button>
|
<button primary>Archive</button>
|
||||||
</ion-item-options>
|
</ion-item-options>
|
||||||
</ion-item-sliding>
|
</ion-item-sliding>
|
||||||
|
|
||||||
|
<ion-item-sliding text-wrap detail-push *ng-for="#item of getItems()">
|
||||||
|
<h3>{{item}}</h3>
|
||||||
|
<ion-item-options>
|
||||||
|
<button primary>Archive</button>
|
||||||
|
</ion-item-options>
|
||||||
|
</ion-item-sliding>
|
||||||
|
|
||||||
</ion-list>
|
</ion-list>
|
||||||
|
Reference in New Issue
Block a user