Skip to content

Commit

Permalink
fix(reorder): not trigger click event when reordering
Browse files Browse the repository at this point in the history
- fixes reorder icon animation on iOS
- fixes crash when clicking the reorder icon very quickly

fixes #8362
  • Loading branch information
manucorporat committed Oct 2, 2016
1 parent d5f71a4 commit 9b2ae8a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
20 changes: 14 additions & 6 deletions src/components/item/item-reorder-gesture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export class ItemReorderGesture {
}

private onDragStart(ev: any): boolean {
if (this.selectedItemEle) {
return false;
}
let reorderElement = ev.target;
if (reorderElement.nodeName !== 'ION-REORDER') {
return false;
Expand Down Expand Up @@ -90,7 +93,7 @@ export class ItemReorderGesture {
if (overItem) {
let toIndex = indexForItem(overItem);
if (toIndex !== undefined && (toIndex !== this.lastToIndex || this.emptyZone)) {
let fromIndex = indexForItem(this.selectedItemEle);
let fromIndex = indexForItem(selectedItem);
this.lastToIndex = toIndex;
this.lastYcoord = posY;
this.emptyZone = false;
Expand All @@ -106,21 +109,26 @@ export class ItemReorderGesture {
(<any>selectedItem.style)[CSS.transform] = `translateY(${ydiff}px)`;
}

private onDragEnd() {
if (!this.selectedItemEle) {
private onDragEnd(ev: any) {
let selectedItem = this.selectedItemEle;
if (!selectedItem) {
return;
}
if (ev) {
ev.preventDefault();
ev.stopPropagation();
}

let toIndex = this.lastToIndex;
let fromIndex = indexForItem(this.selectedItemEle);
let fromIndex = indexForItem(selectedItem);
let reorderInactive = () => {
this.selectedItemEle.style.transition = '';
this.selectedItemEle.classList.remove(ITEM_REORDER_ACTIVE);
this.selectedItemEle = null;
};

if (toIndex === fromIndex) {
this.selectedItemEle.style.transition = 'transform 200ms ease-in-out';
selectedItem.style.transition = 'transform 200ms ease-in-out';
setTimeout(reorderInactive, 200);
} else {
reorderInactive();
Expand All @@ -145,7 +153,7 @@ export class ItemReorderGesture {
* @private
*/
destroy() {
this.onDragEnd();
this.onDragEnd(null);
this.events.unlistenAll();
this.events = null;
this.reorderList = null;
Expand Down
4 changes: 2 additions & 2 deletions src/components/item/item-reorder.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ ion-reorder {
font-size: 1.7em;
opacity: .25;

transform: translate3d(120%, 0, 0);
transform: translate3d(160%, 0, 0);

transition: transform 125ms ease-in;
transition: transform 140ms ease-in;

pointer-events: all;
touch-action: manipulation;
Expand Down
9 changes: 8 additions & 1 deletion src/components/item/item-reorder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Directive, ElementRef, EventEmitter, forwardRef, Input, NgZone, Renderer, Inject, Optional, Output } from '@angular/core';
import { Component, Directive, ElementRef, EventEmitter, forwardRef, HostListener, Input, NgZone, Renderer, Inject, Optional, Output } from '@angular/core';

import { Content } from '../content/content';
import { CSS, zoneRafFrames } from '../../util/dom';
Expand Down Expand Up @@ -328,6 +328,13 @@ export class Reorder {
return findReorderItem(node, null);
}

@HostListener('click', ['$event'])
onClick(ev) {
// Stop propagation if click event reaches ion-reorder
ev.preventDefault();
ev.stopPropagation();
}

}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/components/item/item.ios.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ $item-ios-sliding-content-background: $list-ios-background-color !default;
font-size: $item-ios-body-text-font-size;
color: $list-ios-text-color;
background-color: $list-ios-background-color;
transition-duration: 200ms;
transition: background-color 200ms linear;
}

.item-ios.activated {
Expand Down
2 changes: 1 addition & 1 deletion src/components/item/test/reorder/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<ion-list [reorder]="isReordering" (ionItemReorder)="reorder($event)">
<ion-item-sliding *ngFor="let item of items">
<button ion-item (click)="clickedButton(item)">
Sliding item {{item}}
<h2>Sliding item {{item}}</h2>
</button>
<ion-item-options side="right" icon-left>
<button ion-button color='danger'>
Expand Down

0 comments on commit 9b2ae8a

Please sign in to comment.