Skip to content

Commit 73b750f

Browse files
committed
fix(listView): only allow one swipeable item open. Fixes #763
1 parent 678cf1a commit 73b750f

File tree

2 files changed

+48
-20
lines changed

2 files changed

+48
-20
lines changed

js/ext/angular/src/directive/ionicList.js

+1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ angular.module('ionic.ui.list', ['ngAnimate'])
229229
var destroyShowReorderWatch = $scope.$watch('showReorder', function(val) {
230230
if(val) {
231231
$element[0].classList.add('item-options-hide');
232+
$scope.listView && $scope.listView.clearDragEffects();
232233
} else if(val === false) {
233234
// false checking is because it could be undefined
234235
// if its undefined then we don't care to do anything

js/views/listView.js

+47-20
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
drag: function(e) {
1717
},
1818
end: function(e) {
19+
},
20+
isSameItem: function(item) {
21+
return false;
1922
}
2023
};
2124

@@ -27,6 +30,7 @@
2730
};
2831

2932
SlideDrag.prototype = new DragOp();
33+
3034
SlideDrag.prototype.start = function(e) {
3135
var content, buttons, offsetX, buttonsWidth;
3236

@@ -64,6 +68,27 @@
6468
};
6569
};
6670

71+
/**
72+
* Check if this is the same item that was previously dragged.
73+
*/
74+
SlideDrag.prototype.isSameItem = function(op) {
75+
if(op._lastDrag && this._currentDrag) {
76+
return this._currentDrag.content == op._lastDrag.content;
77+
}
78+
return false;
79+
};
80+
81+
SlideDrag.prototype.clean = function(e) {
82+
var lastDrag = this._lastDrag;
83+
84+
if(!lastDrag) return;
85+
86+
ionic.requestAnimationFrame(function() {
87+
lastDrag.content.style[ionic.CSS.TRANSITION] = '';
88+
lastDrag.content.style[ionic.CSS.TRANSFORM] = 'translate3d(0, 0, 0)';
89+
});
90+
};
91+
6792
SlideDrag.prototype.drag = ionic.animationFrameThrottle(function(e) {
6893
var buttonsWidth;
6994

@@ -124,21 +149,7 @@
124149

125150
}
126151

127-
// var content = this._currentDrag.content;
128-
129-
// var onRestingAnimationEnd = function(e) {
130-
// if(e.propertyName == '-webkit-transform') {
131-
// if(content) content.classList.remove(ITEM_SLIDING_CLASS);
132-
// }
133-
// e.target.removeEventListener('webkitTransitionEnd', onRestingAnimationEnd);
134-
// };
135-
136152
ionic.requestAnimationFrame(function() {
137-
// var currentX = parseFloat(_this._currentDrag.content.style[ionic.CSS.TRANSFORM].replace('translate3d(', '').split(',')[0]) || 0;
138-
// if(currentX !== restingPoint) {
139-
// _this._currentDrag.content.classList.add(ITEM_SLIDING_CLASS);
140-
// _this._currentDrag.content.addEventListener('webkitTransitionEnd', onRestingAnimationEnd);
141-
// }
142153
if(restingPoint === 0) {
143154
_this._currentDrag.content.style[ionic.CSS.TRANSFORM] = '';
144155
} else {
@@ -148,9 +159,9 @@
148159

149160

150161
// Kill the current drag
162+
_this._lastDrag = _this._currentDrag;
151163
_this._currentDrag = null;
152164

153-
154165
// We are done, notify caller
155166
doneCallback && doneCallback();
156167
});
@@ -396,10 +407,22 @@
396407
}
397408
},
398409

410+
/**
411+
* Clear any active drag effects on the list.
412+
*/
413+
clearDragEffects: function() {
414+
if(this._lastDragOp) {
415+
this._lastDragOp.clean && this._lastDragOp.clean();
416+
this._lastDragOp = null;
417+
}
418+
},
419+
399420
_initDrag: function() {
400421
//ionic.views.ListView.__super__._initDrag.call(this);
401422

402-
//this._isDragging = false;
423+
// Store the last one
424+
this._lastDragOp = this._dragOp;
425+
403426
this._dragOp = null;
404427
},
405428

@@ -418,8 +441,12 @@
418441
_startDrag: function(e) {
419442
var _this = this;
420443

444+
var didStart = false;
445+
421446
this._isDragging = false;
422447

448+
var lastDragOp = this._lastDragOp;
449+
423450
// Check if this is a reorder drag
424451
if(ionic.DomUtil.getParentOrSelfWithClass(e.target, ITEM_DRAG_CLASS) && (e.gesture.direction == 'up' || e.gesture.direction == 'down')) {
425452
var item = this._getItem(e.target);
@@ -435,7 +462,6 @@
435462
});
436463
this._dragOp.start(e);
437464
e.preventDefault();
438-
return;
439465
}
440466
}
441467

@@ -448,12 +474,13 @@
448474
this._dragOp = new SlideDrag({ el: this.el });
449475
this._dragOp.start(e);
450476
e.preventDefault();
451-
return;
452477
}
453478
}
454479

455-
// We aren't handling it, so pass it up the chain
456-
//ionic.views.ListView.__super__._startDrag.call(this, e);
480+
// If we had a last drag operation and this is a new one on a different item, clean that last one
481+
if(lastDragOp && this._dragOp && !this._dragOp.isSameItem(lastDragOp) && e.defaultPrevented) {
482+
lastDragOp.clean && lastDragOp.clean();
483+
}
457484
},
458485

459486

0 commit comments

Comments
 (0)