Skip to content

Commit 7e06fb8

Browse files
committed
Restores absolute values for boundaries
1 parent 129dd8a commit 7e06fb8

4 files changed

Lines changed: 18 additions & 26 deletions

File tree

playground/src/examples/MoreChatHeads.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export default class MoreChatHeads extends Component {
111111
<View style={styles.markerContainer}><View style={[styles.marker, {top: 140}]} /></View>
112112
<Interactable.View
113113
snapPoints={ snap }
114-
dragWithSpring={{tension: 2000, damping: 0.5}}
114+
// dragWithSpring={{tension: 2000, damping: 0.5}}
115115
gravityPoints={ gravity }
116116
onStop={this.onStopInteraction}
117117
initialPosition={{x: -140, y: -250}}>

playground/src/interactable/Animator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default class PhysicsAnimator {
4545

4646
let dx = 0;
4747
let {vx,vy} = physicsObject
48-
console.log( physicsObject )
48+
// console.log( physicsObject )
4949

5050
if ( Math.abs(vx) > ANIMATOR_PAUSE_ZERO_VELOCITY ) {
5151
dx = deltaTime * vx;

playground/src/interactable/Behaviors.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ export default {
3434

3535
let { vx, vy } = state
3636

37-
if (minPoint.x >= x && vx < 0) {
37+
if (minPoint.x > x && vx < 0) {
3838
state.vx = -vx * bounce
3939
}
40-
if (minPoint.y >= y && vy < 0) {
40+
if (minPoint.y > y && vy < 0) {
4141
state.vy= -vy * bounce
4242
}
43-
if (maxPoint.x <= x && vx > 0) {
43+
if (maxPoint.x < x && vx > 0) {
4444
state.vx = -vx * bounce
4545
}
46-
if (maxPoint.y <= y && vy > 0) {
46+
if (maxPoint.y < y && vy > 0) {
4747
state.vy = -vy * bounce
4848
}
4949
}
@@ -81,8 +81,8 @@ export default {
8181
doFrame: (options, deltaTime, state, coords) => {
8282
if( !Utils.isPointInArea( coords, options.influence) ) return;
8383

84-
let dx = coords.dx - options.x0;
85-
let dy = coords.dy - options.y0;
84+
let dx = coords.x - options.x0;
85+
let dy = coords.y - options.y0;
8686
let dr = Math.sqrt(dx * dx + dy * dy);
8787
if (!dr) return;
8888

playground/src/interactable/InteractableView.js

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -207,20 +207,10 @@ export default function injectDependencies( Animated, PanResponder ){
207207
this.lastEnd = offset
208208
console.log( offset )
209209

210-
// Set relative boundaries to not to drag after them
211-
if( this.propAreas.boundaries ){
212-
let {minPoint, maxPoint} = this.propAreas.boundaries.influence
213-
this.dragBoundaries = {
214-
minPoint: { x: minPoint.x - offset.x, y: minPoint.y - offset.y },
215-
maxPoint: { x: maxPoint.x - offset.x, y: maxPoint.y - offset.y }
216-
}
217-
}
218-
else {
219-
this.dragBoundaries = {}
220-
}
210+
// Set boundaries to fast access
211+
this.dragBoundaries = this.propAreas.boundaries ? this.propAreas.boundaries.influence : {}
221212

222213
// Prepare the animation
223-
let pos = {x: 0, y: 0}
224214
this.props.onDrag({state: 'start', x: offset.x, y: offset.y})
225215
this.dragStartLocation = { x: ev.x, y: ev.y }
226216
this.animator.removeTempBehaviors();
@@ -238,9 +228,11 @@ export default function injectDependencies( Animated, PanResponder ){
238228
}
239229

240230
onDragging({dx, dy}){
241-
let animated = this.getAnimated()
242-
let x = dx + animated.x._offset
243-
let y = dy + animated.y._offset
231+
let pos = this.getTranslation()
232+
let x = dx + pos.x
233+
let y = dy + pos.y
234+
235+
console.log( this.dragBoundaries.minPoint )
244236

245237
let {minPoint, maxPoint} = this.dragBoundaries
246238
if( !this.props.verticalOnly ){
@@ -267,14 +259,14 @@ export default function injectDependencies( Animated, PanResponder ){
267259
this.dragBehavior = null;
268260
this.animator.isDragging = false
269261

270-
let { animator, horizontalOnly, verticalOnly, dragWithSprings, boundaies } = this
262+
let { animator, horizontalOnly, verticalOnly, dragWithSprings } = this
271263

272264

273265
let velocity = animator.getVelocity();
274266
if (horizontalOnly) velocity.y = 0;
275267
if (verticalOnly) velocity.x = 0;
276268

277-
let toss = dragWithSprings && dragWithSprings.toss || this.props.dragToss;
269+
let toss = (dragWithSprings && dragWithSprings.toss) || this.props.dragToss;
278270
let {x,y} = this.getTranslation()
279271
let projectedCenter = {
280272
x: x + toss * velocity.x,
@@ -283,7 +275,7 @@ export default function injectDependencies( Animated, PanResponder ){
283275

284276
console.log( 'pc', projectedCenter, velocity)
285277
let snapPoint = Utils.findClosest(projectedCenter, this.props.snapPoints);
286-
let targetSnapPointId = snapPoint && snapPoint.id || "";
278+
let targetSnapPointId = (snapPoint && snapPoint.id) || "";
287279

288280
this.props.onDrag({ state: 'end', x: x, y: y, targetSnapPointId })
289281

0 commit comments

Comments
 (0)