Skip to content
This repository has been archived by the owner on Nov 27, 2022. It is now read-only.

Commit

Permalink
fix: don't consider velocity and gesture distance if gesture didn't end
Browse files Browse the repository at this point in the history
closes #806, closes #809
  • Loading branch information
satya164 committed Jun 19, 2019
1 parent c604ddb commit 01bc244
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"lint": "eslint --ext .js,.ts,.tsx .",
"release": "release-it",
"example": "yarn --cwd example",
"bootstrap": "yarn && yarn example",
"bootstrap": "yarn example && yarn",
"prepare": "bob build"
},
"publishConfig": {
Expand Down
21 changes: 14 additions & 7 deletions src/Pager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const {
Clock,
Value,
onChange,
and,
abs,
add,
block,
Expand Down Expand Up @@ -188,7 +189,7 @@ export default class Pager<T extends Route> extends React.Component<Props<T>> {
// Current state of the gesture
private velocityX = new Value(0);
private gestureX = new Value(0);
private gestureState = new Value(State.END);
private gestureState = new Value(State.UNDETERMINED);
private offsetX = new Value(0);

// Current progress of the page (translateX value)
Expand Down Expand Up @@ -415,6 +416,7 @@ export default class Pager<T extends Route> extends React.Component<Props<T>> {
divide(abs(this.velocityX), this.velocityX),
0
);

private extrapolatedPosition = add(
this.gestureX,
multiply(
Expand Down Expand Up @@ -514,14 +516,19 @@ export default class Pager<T extends Route> extends React.Component<Props<T>> {
// Stop animations while we're dragging
stopClock(this.clock),
],

cond(eq(this.gestureState, State.END), [
[
set(this.isSwiping, FALSE),
this.transitionTo(
cond(
greaterThan(
abs(this.extrapolatedPosition),
divide(this.layoutWidth, 2)
and(
// We should consider velocity and gesture distance only when a swipe ends
// The gestureX value will be non-zero (truthy) when swipe has happened
// For other factors such as state update, the velocity and gesture distance don't matter
this.gestureX,
greaterThan(
abs(this.extrapolatedPosition),
divide(this.layoutWidth, 2)
)
),
// For swipe gesture, to calculate the index, determine direction and add to index
// When the user swipes towards the left, we transition to the next tab
Expand All @@ -546,7 +553,7 @@ export default class Pager<T extends Route> extends React.Component<Props<T>> {
this.index
)
),
])
]
),
this.progress,
]);
Expand Down

0 comments on commit 01bc244

Please sign in to comment.