The logic in onPanResponderRelease makes it so that if draggable is not in the dropzone when it is released, then reset returns to 0,0 ( these are the lines calling it ).
Removing this logic is not all that you should do. You must set the offset and reset the value of this.state.pan to onPanResponderRelease . To do this, you need to track the value.
In componentDidMount add the following:
this.currentPanValue = {x: 0, y: 0}; this.panListener = this.state.pan.addListener((value) => this.currentPanValue = value);
Then in componentWillUnmount :
this.state.pan.removeListener(this.panListener);
Now that you have the current value, you simply add it to the PanResponder:
onPanResponderRelease: (e, gestureState) => { this.state.pan.setOffset({x: this.currentPanValue.x, y: this.currentPanValue.y}); this.state.pan.setValue({x: 0, y: 0}); },
It seems more complicated than it really is. Basically, you just set the offset from 0/0, and then set the value to 0/0 so that when you move it again after releasing it, it doesn't go back to 0/0 before moving back to where your finger is. It also ensures that you have a current position ... which you will probably need at some point.
source share