From 1758efa5c39fb0fb13b155a06c5a8e963068df08 Mon Sep 17 00:00:00 2001 From: Anton Tanderup Date: Mon, 30 Sep 2019 13:25:16 +0200 Subject: [PATCH 1/3] Reset sibling items when item is moved back --- lib/DragSortableView.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/lib/DragSortableView.js b/lib/DragSortableView.js index 6889c40..364e5bd 100644 --- a/lib/DragSortableView.js +++ b/lib/DragSortableView.js @@ -182,6 +182,40 @@ export default class DragSortableView extends Component{ } }) + } else if (this.touchCurItem.moveToIndex === this.touchCurItem.index) { + + // If item is moved back to initial position, sibling items need to be moved back + const itemAbove = this.state.dataSource[this.touchCurItem.index + 1]; + if (itemAbove && !this.movingAboveItemBack) { + this.movingAboveItemBack = true; + Animated.timing( + itemAbove.position, + { + toValue: {x: parseInt(itemAbove.originLeft),y: parseInt(itemAbove.originTop)}, + duration: slideDuration, + easing: Easing.out(Easing.quad), + useNativeDriver: true, + } + ).start( () => { + this.movingAboveItemBack = false; + }); + } + const itemBelow = this.state.dataSource[this.touchCurItem.index - 1]; + if (itemBelow && !this.movingBelowItemBack) { + this.movingBelowItemBack = true; + Animated.timing( + itemBelow.position, + { + toValue: {x: parseInt(itemBelow.originLeft),y: parseInt(itemBelow.originTop)}, + duration: slideDuration, + easing: Easing.out(Easing.quad), + useNativeDriver: true, + } + ).start(() => { + this.movingBelowItemBack = false; + }); + } + } } From 6eb0b778274c9c21bfc47b33b9ed5e06f3e827c0 Mon Sep 17 00:00:00 2001 From: Anton Tanderup Date: Mon, 30 Sep 2019 13:26:33 +0200 Subject: [PATCH 2/3] Remove useNativeDrive (not used on master) --- lib/DragSortableView.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/DragSortableView.js b/lib/DragSortableView.js index 364e5bd..aa158c8 100644 --- a/lib/DragSortableView.js +++ b/lib/DragSortableView.js @@ -209,7 +209,6 @@ export default class DragSortableView extends Component{ toValue: {x: parseInt(itemBelow.originLeft),y: parseInt(itemBelow.originTop)}, duration: slideDuration, easing: Easing.out(Easing.quad), - useNativeDriver: true, } ).start(() => { this.movingBelowItemBack = false; From 9e657ce3c4d4de48735b8a4276d3f5784f6936ce Mon Sep 17 00:00:00 2001 From: Anton Tanderup Date: Mon, 30 Sep 2019 13:36:11 +0200 Subject: [PATCH 3/3] dont useNativeDriver --- lib/DragSortableView.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/DragSortableView.js b/lib/DragSortableView.js index aa158c8..47fe6c1 100644 --- a/lib/DragSortableView.js +++ b/lib/DragSortableView.js @@ -194,7 +194,6 @@ export default class DragSortableView extends Component{ toValue: {x: parseInt(itemAbove.originLeft),y: parseInt(itemAbove.originTop)}, duration: slideDuration, easing: Easing.out(Easing.quad), - useNativeDriver: true, } ).start( () => { this.movingAboveItemBack = false;