Skip to content

Commit 9b2ae8a

Browse files
committed
fix(reorder): not trigger click event when reordering
- fixes reorder icon animation on iOS - fixes crash when clicking the reorder icon very quickly fixes #8362
1 parent d5f71a4 commit 9b2ae8a

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

src/components/item/item-reorder-gesture.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export class ItemReorderGesture {
3434
}
3535

3636
private onDragStart(ev: any): boolean {
37+
if (this.selectedItemEle) {
38+
return false;
39+
}
3740
let reorderElement = ev.target;
3841
if (reorderElement.nodeName !== 'ION-REORDER') {
3942
return false;
@@ -90,7 +93,7 @@ export class ItemReorderGesture {
9093
if (overItem) {
9194
let toIndex = indexForItem(overItem);
9295
if (toIndex !== undefined && (toIndex !== this.lastToIndex || this.emptyZone)) {
93-
let fromIndex = indexForItem(this.selectedItemEle);
96+
let fromIndex = indexForItem(selectedItem);
9497
this.lastToIndex = toIndex;
9598
this.lastYcoord = posY;
9699
this.emptyZone = false;
@@ -106,21 +109,26 @@ export class ItemReorderGesture {
106109
(<any>selectedItem.style)[CSS.transform] = `translateY(${ydiff}px)`;
107110
}
108111

109-
private onDragEnd() {
110-
if (!this.selectedItemEle) {
112+
private onDragEnd(ev: any) {
113+
let selectedItem = this.selectedItemEle;
114+
if (!selectedItem) {
111115
return;
112116
}
117+
if (ev) {
118+
ev.preventDefault();
119+
ev.stopPropagation();
120+
}
113121

114122
let toIndex = this.lastToIndex;
115-
let fromIndex = indexForItem(this.selectedItemEle);
123+
let fromIndex = indexForItem(selectedItem);
116124
let reorderInactive = () => {
117125
this.selectedItemEle.style.transition = '';
118126
this.selectedItemEle.classList.remove(ITEM_REORDER_ACTIVE);
119127
this.selectedItemEle = null;
120128
};
121129

122130
if (toIndex === fromIndex) {
123-
this.selectedItemEle.style.transition = 'transform 200ms ease-in-out';
131+
selectedItem.style.transition = 'transform 200ms ease-in-out';
124132
setTimeout(reorderInactive, 200);
125133
} else {
126134
reorderInactive();
@@ -145,7 +153,7 @@ export class ItemReorderGesture {
145153
* @private
146154
*/
147155
destroy() {
148-
this.onDragEnd();
156+
this.onDragEnd(null);
149157
this.events.unlistenAll();
150158
this.events = null;
151159
this.reorderList = null;

src/components/item/item-reorder.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ ion-reorder {
1616
font-size: 1.7em;
1717
opacity: .25;
1818

19-
transform: translate3d(120%, 0, 0);
19+
transform: translate3d(160%, 0, 0);
2020

21-
transition: transform 125ms ease-in;
21+
transition: transform 140ms ease-in;
2222

2323
pointer-events: all;
2424
touch-action: manipulation;

src/components/item/item-reorder.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Directive, ElementRef, EventEmitter, forwardRef, Input, NgZone, Renderer, Inject, Optional, Output } from '@angular/core';
1+
import { Component, Directive, ElementRef, EventEmitter, forwardRef, HostListener, Input, NgZone, Renderer, Inject, Optional, Output } from '@angular/core';
22

33
import { Content } from '../content/content';
44
import { CSS, zoneRafFrames } from '../../util/dom';
@@ -328,6 +328,13 @@ export class Reorder {
328328
return findReorderItem(node, null);
329329
}
330330

331+
@HostListener('click', ['$event'])
332+
onClick(ev) {
333+
// Stop propagation if click event reaches ion-reorder
334+
ev.preventDefault();
335+
ev.stopPropagation();
336+
}
337+
331338
}
332339

333340
/**

src/components/item/item.ios.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ $item-ios-sliding-content-background: $list-ios-background-color !default;
3333
font-size: $item-ios-body-text-font-size;
3434
color: $list-ios-text-color;
3535
background-color: $list-ios-background-color;
36-
transition-duration: 200ms;
36+
transition: background-color 200ms linear;
3737
}
3838

3939
.item-ios.activated {

src/components/item/test/reorder/main.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<ion-list [reorder]="isReordering" (ionItemReorder)="reorder($event)">
2323
<ion-item-sliding *ngFor="let item of items">
2424
<button ion-item (click)="clickedButton(item)">
25-
Sliding item {{item}}
25+
<h2>Sliding item {{item}}</h2>
2626
</button>
2727
<ion-item-options side="right" icon-left>
2828
<button ion-button color='danger'>

0 commit comments

Comments
 (0)