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

Commit

Permalink
fix: change logic of switching tabs
Browse files Browse the repository at this point in the history
It appears that previous logic was considering velocity in a too aggressive way. So I'd like to get rid of extra velocity multiplication. It should lead to more natural behavior.
  • Loading branch information
osdnk committed Jun 30, 2019
1 parent c6e3c03 commit f8fa30f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -290,7 +290,7 @@ Boolean indicating whether to enable swipe gestures. Swipe gestures are enabled

##### `swipeVelocityImpact`

Determines how relevant is a velocity while calculating next position while swiping. Defaults to `0.01`.
Determines how relevant is a velocity while calculating next position while swiping. Defaults to `0.2`.

##### `onSwipeStart`

Expand Down
17 changes: 3 additions & 14 deletions src/Pager.tsx
Expand Up @@ -80,7 +80,7 @@ const DIRECTION_RIGHT = -1;

const SWIPE_DISTANCE_MINIMUM = 20;

const SWIPE_VELOCITY_IMPACT = 0.01;
const SWIPE_VELOCITY_IMPACT = 0.2;

const SPRING_CONFIG = {
stiffness: 1000,
Expand Down Expand Up @@ -427,20 +427,9 @@ export default class Pager<T extends Route> extends React.Component<Props<T>> {
},
]);

private velocitySignum = cond(
this.velocityX,
divide(abs(this.velocityX), this.velocityX),
0
);

private extrapolatedPosition = add(
this.gestureX,
multiply(
this.velocityX,
this.velocityX,
this.velocitySignum,
this.swipeVelocityImpact
)
multiply(this.velocityX, this.swipeVelocityImpact)
);

private translateX = block([
Expand Down Expand Up @@ -582,7 +571,7 @@ export default class Pager<T extends Route> extends React.Component<Props<T>> {
sub(
this.index,
cond(
greaterThan(this.velocitySignum, 0),
greaterThan(this.extrapolatedPosition, 0),
I18nManager.isRTL ? DIRECTION_RIGHT : DIRECTION_LEFT,
I18nManager.isRTL ? DIRECTION_LEFT : DIRECTION_RIGHT
)
Expand Down

0 comments on commit f8fa30f

Please sign in to comment.