@@ -19,7 +19,7 @@ export default function injectDependencies( Animated, PanResponder ){
1919 gravityPoints : PropTypes . array ,
2020 horizontalOnly : PropTypes . bool ,
2121 verticalOnly : PropTypes . bool ,
22- dragWithSpring : PropTypes . bool ,
22+ dragWithSpring : PropTypes . objet ,
2323 dragEnabled : PropTypes . bool ,
2424 animatedValueX : PropTypes . instanceOf ( Animated . Value ) ,
2525 animatedValueY : PropTypes . instanceOf ( Animated . Value ) ,
@@ -64,9 +64,6 @@ export default function injectDependencies( Animated, PanResponder ){
6464 // Cache when the view is inside of an alert area
6565 this . insideAlertAreas = { }
6666
67- // Save the last animation end position to report good coordinates in the events
68- this . lastEnd = { x : 0 , y : 0 }
69-
7067 // cache calculated areas
7168 this . propAreas = {
7269 alert : [ ] ,
@@ -82,13 +79,13 @@ export default function injectDependencies( Animated, PanResponder ){
8279 let { x, y} = this . getAnimated ( props )
8380 x . setValue ( props . initialPosition . x )
8481 y . setValue ( props . initialPosition . y )
82+
83+ // Save the last animation end position to report good coordinates in the events
84+ this . lastEnd = { ...this . initialPosition }
8585 }
8686
8787 render ( ) {
8888 let { x, y } = this . getAnimated ( )
89- this . lastX = x
90- this . lastY = y
91-
9289
9390 let position = {
9491 transform : [
@@ -106,26 +103,21 @@ export default function injectDependencies( Animated, PanResponder ){
106103 }
107104
108105 getTranslation ( ) {
109- let animated = this . getAnimated ( )
110- return {
111- x : animated . x . _value ,
112- y : animated . y . _value
113- }
114- }
115- getAbsoluteTranslation ( ) {
116- let { x, y} = this . getAnimated ( )
106+ let { x, y} = this . getAnimated ( )
117107 return {
118108 x : x . _value + x . _offset ,
119109 y : y . _value + y . _offset
120110 }
121111 }
122112
123113 setTranslationX ( tx ) {
124- ( this . props . animatedValueX || this . animated . x ) . setValue ( tx )
114+ let animated = this . props . animatedValueX || this . animated . x
115+ animated . setValue ( tx - animated . _offset )
125116 }
126117
127118 setTranslationY ( ty ) {
128- ( this . props . animatedValueY || this . animated . y ) . setValue ( ty )
119+ let animated = this . props . animatedValueY || this . animated . y
120+ animated . setValue ( ty - animated . _offset )
129121 }
130122
131123 setTranslation ( tx , ty ) {
@@ -148,6 +140,8 @@ export default function injectDependencies( Animated, PanResponder ){
148140
149141 animate ( dx , dy ) {
150142 if ( ! dx && ! dy ) return
143+ let animated = this . getAnimated ( )
144+ console . log ( dx + animated . x . _value + animated . x . _offset )
151145
152146 let { x, y} = this . getTranslation ( )
153147 this . setTranslation ( x + dx , y + dy )
@@ -177,9 +171,6 @@ export default function injectDependencies( Animated, PanResponder ){
177171
178172 onPanResponderRelease : ( ) => {
179173 this . endDrag ( )
180- let { x, y} = this . getAnimated ( )
181- x . flattenOffset ( )
182- y . flattenOffset ( )
183174 }
184175 } )
185176 }
@@ -214,6 +205,7 @@ export default function injectDependencies( Animated, PanResponder ){
214205
215206 // Save the offset for triggering events with the right coordinates
216207 this . lastEnd = offset
208+ console . log ( offset )
217209
218210 // Set relative boundaries to not to drag after them
219211 if ( this . propAreas . boundaries ) {
@@ -228,8 +220,8 @@ export default function injectDependencies( Animated, PanResponder ){
228220 }
229221
230222 // Prepare the animation
231- let pos = this . getTranslation ( )
232- this . props . onDrag ( { state : 'start' , x : pos . x + this . lastEnd . x , y : pos . y + this . lastEnd . y } )
223+ let pos = { x : 0 , y : 0 }
224+ this . props . onDrag ( { state : 'start' , x : offset . x , y : offset . y } )
233225 this . dragStartLocation = { x : ev . x , y : ev . y }
234226 this . animator . removeTempBehaviors ( ) ;
235227 this . animator . isDragging = true
@@ -246,22 +238,28 @@ export default function injectDependencies( Animated, PanResponder ){
246238 }
247239
248240 onDragging ( { dx, dy} ) {
241+ let animated = this . getAnimated ( )
242+ let x = dx + animated . x . _offset
243+ let y = dy + animated . y . _offset
244+
249245 let { minPoint, maxPoint} = this . dragBoundaries
250246 if ( ! this . props . verticalOnly ) {
251247 if ( minPoint ) {
252- if ( minPoint . x > dx ) dx = minPoint . x
253- if ( maxPoint . x < dx ) dx = maxPoint . x
248+ if ( minPoint . x > x ) x = minPoint . x
249+ if ( maxPoint . x < x ) x = maxPoint . x
254250 }
255- this . dragBehavior . x0 = dx
251+ this . dragBehavior . x0 = x
256252 }
257253
258254 if ( ! this . props . horizontalOnly ) {
259255 if ( minPoint ) {
260- if ( minPoint . y > dy ) dy = minPoint . y
261- if ( maxPoint . y < dy ) dy = maxPoint . y
256+ if ( minPoint . y > y ) y = minPoint . y
257+ if ( maxPoint . y < y ) y = maxPoint . y
262258 }
263- this . dragBehavior . y0 = dy
259+ this . dragBehavior . y0 = y
264260 }
261+
262+ console . log ( this . dragBehavior )
265263 }
266264
267265 endDrag ( ) {
@@ -279,19 +277,23 @@ export default function injectDependencies( Animated, PanResponder ){
279277 let toss = dragWithSprings && dragWithSprings . toss || this . props . dragToss ;
280278 let { x, y} = this . getTranslation ( )
281279 let projectedCenter = {
282- x : x + this . lastEnd . x + toss * velocity . x ,
283- y : y + this . lastEnd . y + toss * velocity . y
280+ x : x + toss * velocity . x ,
281+ y : y + toss * velocity . y
284282 } ;
285283
286- console . log ( 'pc' , projectedCenter , velocity , this . lastEnd )
284+ console . log ( 'pc' , projectedCenter , velocity )
287285 let snapPoint = Utils . findClosest ( projectedCenter , this . props . snapPoints ) ;
288286 let targetSnapPointId = snapPoint && snapPoint . id || "" ;
289287
290- this . props . onDrag ( { state : 'end' , x : x + this . lastEnd . x , y : y + this . lastEnd . y , targetSnapPointId } )
288+ this . props . onDrag ( { state : 'end' , x : x , y : y , targetSnapPointId } )
291289
292290 this . addTempSnapToPointBehavior ( snapPoint ) ;
293291 this . addTempBoundaries ( ) ;
294292
293+ let animated = this . getAnimated ( )
294+ animated . x . flattenOffset ( )
295+ animated . y . flattenOffset ( )
296+
295297 // Restore text selection
296298 if ( document ) {
297299 document . body . userSelect = this . userSelectCache || ''
@@ -314,7 +316,7 @@ export default function injectDependencies( Animated, PanResponder ){
314316 }
315317
316318 addTempSnapToPointBehavior ( snapPoint ) {
317- if ( ! snapPoint == null ) return ;
319+ if ( ! snapPoint ) return ;
318320 let { snapPoints, onSnap, onSnapStart } = this . props
319321
320322 let index = snapPoints . indexOf ( snapPoint )
@@ -346,8 +348,8 @@ export default function injectDependencies( Animated, PanResponder ){
346348
347349 setVelocity ( velocity ) {
348350 if ( this . dragBehavior ) return ;
349- this . velocity = velocity ;
350- this . animator . setTargetVelocity ( this , this . velocity ) ;
351+ this . animator . vx = velocity . x
352+ this . animator . vy = velocity . y
351353 this . endDrag ( ) ;
352354 }
353355
0 commit comments