mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
fix(listView): reordering up is more responsive, fix scrolling error
Closes #1202
This commit is contained in:
@@ -191,9 +191,10 @@
|
||||
ReorderDrag.prototype = new DragOp();
|
||||
|
||||
ReorderDrag.prototype._moveElement = function(e) {
|
||||
var y = e.gesture.center.pageY -
|
||||
this._currentDrag.elementHeight +
|
||||
var y = e.gesture.center.pageY +
|
||||
this.scrollView.getValues().top -
|
||||
this.scrollView.__container.offsetTop -
|
||||
(this._currentDrag.elementHeight / 2) -
|
||||
this.listEl.offsetTop;
|
||||
this.el.style[ionic.CSS.TRANSFORM] = 'translate3d(0, '+y+'px, 0)';
|
||||
};
|
||||
@@ -223,17 +224,19 @@
|
||||
|
||||
ReorderDrag.prototype.drag = ionic.animationFrameThrottle(function(e) {
|
||||
// We really aren't dragging
|
||||
var self = this;
|
||||
if(!this._currentDrag) {
|
||||
return;
|
||||
}
|
||||
|
||||
var scrollY = 0;
|
||||
var pageY = e.gesture.center.pageY;
|
||||
var offset = this.listEl.offsetTop + this.scrollView.__container.offsetTop;
|
||||
|
||||
//If we have a scrollView, check scroll boundaries for dragged element and scroll if necessary
|
||||
if (this.scrollView) {
|
||||
var container = this.scrollEl;
|
||||
|
||||
var container = this.scrollView.__container;
|
||||
scrollY = this.scrollView.getValues().top;
|
||||
|
||||
var containerTop = container.offsetTop;
|
||||
@@ -242,10 +245,18 @@
|
||||
|
||||
if (e.gesture.deltaY < 0 && pixelsPastTop > 0 && scrollY > 0) {
|
||||
this.scrollView.scrollBy(null, -pixelsPastTop);
|
||||
//Trigger another drag so the scrolling keeps going
|
||||
setTimeout(function() {
|
||||
self.drag(e);
|
||||
}.bind(this));
|
||||
}
|
||||
if (e.gesture.deltaY > 0 && pixelsPastBottom > 0) {
|
||||
if (scrollY < this.scrollView.getScrollMax().top) {
|
||||
this.scrollView.scrollBy(null, pixelsPastBottom);
|
||||
//Trigger another drag so the scrolling keeps going
|
||||
setTimeout(function() {
|
||||
self.drag(e);
|
||||
}.bind(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -259,7 +270,7 @@
|
||||
if(this._isDragging) {
|
||||
this._moveElement(e);
|
||||
|
||||
this._currentDrag.currentY = scrollY + pageY - this._currentDrag.placeholder.parentNode.offsetTop;
|
||||
this._currentDrag.currentY = scrollY + pageY - offset;
|
||||
|
||||
this._reorderItems();
|
||||
}
|
||||
@@ -279,13 +290,14 @@
|
||||
var bottomSibling = siblings[Math.min(siblings.length, index+1)];
|
||||
var thisOffsetTop = this._currentDrag.currentY;// + this._currentDrag.startOffsetTop;
|
||||
|
||||
if(topSibling && (thisOffsetTop < topSibling.offsetTop + topSibling.offsetHeight/2)) {
|
||||
if(topSibling && (thisOffsetTop < topSibling.offsetTop + topSibling.offsetHeight)) {
|
||||
ionic.DomUtil.swapNodes(this._currentDrag.placeholder, topSibling);
|
||||
return index - 1;
|
||||
} else if(bottomSibling && thisOffsetTop > (bottomSibling.offsetTop + bottomSibling.offsetHeight/2)) {
|
||||
} else if(bottomSibling && thisOffsetTop > (bottomSibling.offsetTop)) {
|
||||
ionic.DomUtil.swapNodes(bottomSibling, this._currentDrag.placeholder);
|
||||
return index + 1;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
ReorderDrag.prototype.end = function(e, doneCallback) {
|
||||
|
||||
@@ -24,6 +24,10 @@
|
||||
</div>
|
||||
</ion-header-bar>
|
||||
|
||||
<ion-header-bar class="bar-positive bar-assertive bar-subheader">
|
||||
<h1 class="title">Subheader</h1>
|
||||
</ion-header-bar>
|
||||
|
||||
<ion-content>
|
||||
<!--
|
||||
Search bar
|
||||
|
||||
Reference in New Issue
Block a user