Skip to content

(reorder fixes:) https://github.com/driftyco/ionic/issues/7522 #8818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/components/item/item-reorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ export class ItemReorder {
*/
reorderPrepare() {
let ele = this._element;
// append child to allow reordering to bottom position
ele.insertAdjacentHTML('beforeend', '<div class="ion-reorder-temp-item item-block"></div>');
let children: any = ele.children;
for (let i = 0, ilen = children.length; i < ilen; i++) {
var child = children[i];
Expand All @@ -221,6 +223,13 @@ export class ItemReorder {
*/
reorderEmit(fromIndex: number, toIndex: number) {
this.reorderReset();

// fixes bug: https://github.com/driftyco/ionic/issues/8782
let diff = fromIndex - toIndex;
if(diff < 0 ) {
toIndex = toIndex - 1
}

if (fromIndex !== toIndex) {
this._zone.run(() => {
this.ionItemReorder.emit({
Expand All @@ -246,6 +255,9 @@ export class ItemReorder {
* @private
*/
reorderReset() {
// remove temp bottom item.
this._element.querySelector('.ion-reorder-temp-item').remove();

let children = this._element.children;
let len = children.length;

Expand Down Expand Up @@ -276,16 +288,16 @@ export class ItemReorder {
/********* DOM WRITE ********* */
let transform = CSS.transform;
if (toIndex >= lastToIndex) {
for (var i = lastToIndex; i <= toIndex; i++) {
for (var i = lastToIndex; i <= toIndex-1; i++) {
if (i !== fromIndex) {
(<any>children[i]).style[transform] = (i > fromIndex)
(<any>children[i]).style[transform] = (i >= fromIndex)
? `translateY(${-itemHeight}px)` : '';
}
}
}

if (toIndex <= lastToIndex) {
for (var i = toIndex; i <= lastToIndex; i++) {
if (toIndex < lastToIndex) {
for (var i = toIndex; i <= lastToIndex+1; i++) {
if (i !== fromIndex) {
(<any>children[i]).style[transform] = (i < fromIndex)
? `translateY(${itemHeight}px)` : '';
Expand Down