diff --git a/src/components/item/item-sliding-gesture.ts b/src/components/item/item-sliding-gesture.ts index 8d150c3fc1e..025ec1ac5ab 100644 --- a/src/components/item/item-sliding-gesture.ts +++ b/src/components/item/item-sliding-gesture.ts @@ -54,7 +54,6 @@ export class ItemSlidingGesture extends DragGesture { this.closeOpened(); } - // Close all item sliding containers but the selected one this.selectedContainer = container; this.openContainer = container; container.startSliding(ev.center.x); @@ -72,6 +71,8 @@ export class ItemSlidingGesture extends DragGesture { onDragEnd(ev: any) { if (this.selectedContainer) { + ev.preventDefault(); + let openAmount = this.selectedContainer.endSliding(ev.velocityX); this.selectedContainer = null; @@ -109,7 +110,7 @@ export class ItemSlidingGesture extends DragGesture { function getContainer(ev: any): ItemSliding { let ele = closest(ev.target, 'ion-item-sliding', true); if (ele) { - return ele['$ionComponent']; + return (ele)['$ionComponent']; } return null; } diff --git a/src/components/item/item-sliding.ts b/src/components/item/item-sliding.ts index 70da33cde96..82b3c8190b1 100644 --- a/src/components/item/item-sliding.ts +++ b/src/components/item/item-sliding.ts @@ -1,10 +1,9 @@ import {ChangeDetectionStrategy, Component, ContentChildren, ContentChild, Directive, ElementRef, EventEmitter, HostBinding, Input, Optional, Output, QueryList, Renderer, ViewEncapsulation} from '@angular/core'; import {List} from '../list/list'; -import {Ion} from '../ion'; import {Item} from './item'; import {isPresent} from '../../util/util'; -import {CSS} from '../../util/dom'; +import {CSS, nativeRaf, nativeTimeout} from '../../util/dom'; const SWIPE_FACTOR = 1.1; const ELASTIC_FACTOR = 0.55; @@ -22,19 +21,18 @@ export const enum SideFlags { @Directive({ selector: 'ion-item-options', }) -export class ItemOptions extends Ion { +export class ItemOptions { @Input() side: string; @Output() ionSwipe: EventEmitter = new EventEmitter(); - constructor(elementRef: ElementRef, private _renderer: Renderer) { - super(elementRef); + constructor(private _elementRef: ElementRef, private _renderer: Renderer) { } /** * @private */ setCssStyle(property: string, value: string) { - this._renderer.setElementStyle(this.elementRef.nativeElement, property, value); + this._renderer.setElementStyle(this._elementRef.nativeElement, property, value); } /** @@ -48,6 +46,10 @@ export class ItemOptions extends Ion { } } + width() { + return this._elementRef.nativeElement.offsetWidth; + } + } const enum SlidingState { @@ -224,10 +226,14 @@ export class ItemSliding { * @private */ startSliding(startX: number) { + if (this._timer) { + clearTimeout(this._timer); + this._timer = null; + } if (this._openAmount === 0) { + this._optsDirty = true; this._setState(SlidingState.Enabled); } - this._optsDirty = true; this._startX = startX + this._openAmount; this.item.setCssStyle(CSS.transition, 'none'); } @@ -236,7 +242,10 @@ export class ItemSliding { * @private */ moveSliding(x: number): number { - this.calculateOptsWidth(); + if (this._optsDirty) { + this.calculateOptsWidth(); + return; + } let openAmount = this._startX - x; switch (this._sides) { @@ -290,17 +299,20 @@ export class ItemSliding { } calculateOptsWidth() { - if (this._optsDirty) { - this._optsWidthRightSide = 0; - if (this._rightOptions) { - this._optsWidthRightSide = this._rightOptions.width(); + nativeRaf(() => { + if (this._optsDirty) { + this._optsWidthRightSide = 0; + if (this._rightOptions) { + this._optsWidthRightSide = this._rightOptions.width(); + } + + this._optsWidthLeftSide = 0; + if (this._leftOptions) { + this._optsWidthLeftSide = this._leftOptions.width(); + } + this._optsDirty = false; } - this._optsWidthLeftSide = 0; - if (this._leftOptions) { - this._optsWidthLeftSide = this._leftOptions.width(); - } - this._optsDirty = false; - } + }); } /** @@ -317,7 +329,7 @@ export class ItemSliding { if (didEnd) { // TODO: refactor. there must exist a better way // if sliding ended, we wait 400ms until animation finishes - this._timer = setTimeout(() => { + this._timer = nativeTimeout(() => { this._setState(SlidingState.Disabled); this._timer = null; }, 400); @@ -347,6 +359,10 @@ export class ItemSliding { this.setClass('active-slide', state !== SlidingState.Disabled); this.setClass('active-options-right', state === SlidingState.Right); this.setClass('active-options-left', state === SlidingState.Left); + if (state === SlidingState.Disabled || state === SlidingState.Enabled) { + this.setClass('active-swipe-right', false); + this.setClass('active-swipe-left', false); + } } } diff --git a/src/components/item/test/sliding/main.html b/src/components/item/test/sliding/main.html index 00b336efe55..667cd3f02fc 100644 --- a/src/components/item/test/sliding/main.html +++ b/src/components/item/test/sliding/main.html @@ -14,6 +14,32 @@ + + +

HubStruck Notifications

+

A new message from a repo in your network

+

Oceanic Next has joined your network

+ + 10:45 AM + +
+ + + + + + + + + +
+ diff --git a/src/components/tabs/test/advanced/index.ts b/src/components/tabs/test/advanced/index.ts index d65d73f992e..ccc17eba3cb 100644 --- a/src/components/tabs/test/advanced/index.ts +++ b/src/components/tabs/test/advanced/index.ts @@ -137,7 +137,7 @@ class Tab1Page1 { } push() { - this.nav.push(Tab1Page2) + this.nav.push(Tab1Page2); } goBack() { @@ -193,7 +193,7 @@ class Tab1Page2 { constructor(private nav: NavController) {} push() { - this.nav.push(Tab1Page3) + this.nav.push(Tab1Page3); } ionViewWillEnter() { @@ -273,7 +273,7 @@ class Tab2Page1 { constructor(private nav: NavController) {} push() { - this.nav.push(Tab2Page2) + this.nav.push(Tab2Page2); } ionViewWillEnter() { @@ -314,7 +314,7 @@ class Tab2Page2 { constructor(private nav: NavController) {} push() { - this.nav.push(Tab2Page3) + this.nav.push(Tab2Page3); } ionViewWillEnter() {