Skip to content

Commit 35c3225

Browse files
committed
Fixes playground and initial velocity when dragging
1 parent 8d9082b commit 35c3225

6 files changed

Lines changed: 19 additions & 5 deletions

File tree

playground/config/webpack.config.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ module.exports = {
150150
// Support React Native Web
151151
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
152152
'react-native': 'react-native-web',
153-
'react-native-interactable': path.join(__dirname, '../../index.js'),
153+
'react-native-interactable': path.join(__dirname, '../src/interactable/index.js'),
154154
'assets': path.join(__dirname, '../src/assets'),
155155
},
156156
plugins: [

Animator.js renamed to playground/src/interactable/Animator.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@ export default class PhysicsAnimator {
5656
hadMovement = true;
5757
}
5858

59+
// console.log( {dx, dy} )
5960
View.animate( dx, dy )
6061

6162
let cfwnm = hadMovement ? 0 : this.consecutiveFramesWithNoMovement + 1
6263
this.consecutiveFramesWithNoMovement = cfwnm
6364

64-
if (cfwnm >= ANIMATOR_PAUSE_CONSECUTIVE_FRAMES && !this.isDragging) {
65+
if (cfwnm >= ANIMATOR_PAUSE_CONSECUTIVE_FRAMES && !this.isDragging ) {
6566
this.stopRunning();
6667
this.animatorListener.onAnimatorPause();
6768
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export default {
7575
strength: options.strength || 400,
7676
falloff: options.falloff || 40,
7777
damping: options.damping || 0,
78-
influence: options.damping ? Utils.createAreaFromRadius( 1.4 * options.falloff || 40, anchor ) : Utils.createArea( options.influenceArea || {} ),
78+
influence: options.damping ? Utils.createAreaFromRadius( 1.4 * options.falloff || 40, options ) : Utils.createArea( options.influenceArea || {} ),
7979
isTemp,
8080
priority: 1
8181
}),
@@ -94,7 +94,7 @@ export default {
9494
let ax = dx / dr * a;
9595
let ay = dy / dr * a;
9696

97-
state.vx += deltaTime * ax,
97+
state.vx += deltaTime * ax
9898
state.vy += deltaTime * ay
9999
}
100100
},

InteractableView.js renamed to playground/src/interactable/InteractableView.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default function injectDependencies( Animated, PanResponder ){
2121
verticalOnly: PropTypes.bool,
2222
dragWithSprings: PropTypes.bool,
2323
dragEnabled: PropTypes.bool,
24-
// animatedValueX: PropTypes.instanceOf(Animated.Value),
24+
animatedValueX: PropTypes.instanceOf(Animated.Value),
2525
// animatedValueY: PropTypes.instanceOf(Animated.Value),
2626
onSnap: PropTypes.func,
2727
onSnapStart: PropTypes.func,
@@ -86,6 +86,11 @@ export default function injectDependencies( Animated, PanResponder ){
8686

8787
render() {
8888
let { x, y } = this.getAnimated()
89+
console.log( x === this.lastX, y === this.lastY)
90+
this.lastX = x
91+
this.lastY= y
92+
93+
8994
let position = {
9095
transform: [
9196
{ translateX: x }, { translateY: y }
@@ -159,6 +164,7 @@ export default function injectDependencies( Animated, PanResponder ){
159164
onPanResponderGrant: (e, {x0, y0}) => {
160165
let {x,y} = this.getAnimated()
161166
let offset = {x: x._value, y: y._value}
167+
this.lastEnd = offset
162168
x.setOffset( offset.x )
163169
y.setOffset( offset.y )
164170
x.setValue( 0 )
@@ -206,6 +212,8 @@ export default function injectDependencies( Animated, PanResponder ){
206212
this.dragStartLocation = { x: ev.x, y: ev.y }
207213
this.animator.removeTempBehaviors();
208214
this.animator.isDragging = true
215+
this.animator.vx = 0
216+
this.animator.vy = 0
209217
this.addTempDragBehavior( this.props.dragWithSprings );
210218
}
211219

@@ -228,6 +236,7 @@ export default function injectDependencies( Animated, PanResponder ){
228236
y: y + this.lastEnd.y + toss * velocity.y
229237
};
230238

239+
console.log( 'pc', projectedCenter, velocity, this.lastEnd )
231240
let snapPoint = Utils.findClosest(projectedCenter, this.props.snapPoints);
232241
let targetSnapPointId = snapPoint && snapPoint.id || "";
233242

@@ -318,6 +327,7 @@ export default function injectDependencies( Animated, PanResponder ){
318327
}
319328

320329
componentDidUpdate( prevProps ){
330+
console.log('updated')
321331
this.setPropBehaviours( prevProps, this.props )
322332
}
323333

Utils.js renamed to playground/src/interactable/Utils.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@ export default {
2727
findClosest: function( origin, points ){
2828
let minDistance = Infinity;
2929
let closestPoint = null;
30+
let distances = []
3031
points.forEach( point => {
3132
let distance = this.getDistance( point, origin );
33+
distances.push( distance )
3234
if (distance < minDistance) {
3335
minDistance = distance;
3436
closestPoint = point;
3537
}
3638
})
39+
console.log( distances )
3740
return closestPoint
3841
},
3942
getDistance( point, relative ){

0 commit comments

Comments
 (0)