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

Commit f8fa30f

Browse files
authored
fix: change logic of switching tabs
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.
1 parent c6e3c03 commit f8fa30f

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ Boolean indicating whether to enable swipe gestures. Swipe gestures are enabled
290290

291291
##### `swipeVelocityImpact`
292292

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

295295
##### `onSwipeStart`
296296

src/Pager.tsx

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const DIRECTION_RIGHT = -1;
8080

8181
const SWIPE_DISTANCE_MINIMUM = 20;
8282

83-
const SWIPE_VELOCITY_IMPACT = 0.01;
83+
const SWIPE_VELOCITY_IMPACT = 0.2;
8484

8585
const SPRING_CONFIG = {
8686
stiffness: 1000,
@@ -427,20 +427,9 @@ export default class Pager<T extends Route> extends React.Component<Props<T>> {
427427
},
428428
]);
429429

430-
private velocitySignum = cond(
431-
this.velocityX,
432-
divide(abs(this.velocityX), this.velocityX),
433-
0
434-
);
435-
436430
private extrapolatedPosition = add(
437431
this.gestureX,
438-
multiply(
439-
this.velocityX,
440-
this.velocityX,
441-
this.velocitySignum,
442-
this.swipeVelocityImpact
443-
)
432+
multiply(this.velocityX, this.swipeVelocityImpact)
444433
);
445434

446435
private translateX = block([
@@ -582,7 +571,7 @@ export default class Pager<T extends Route> extends React.Component<Props<T>> {
582571
sub(
583572
this.index,
584573
cond(
585-
greaterThan(this.velocitySignum, 0),
574+
greaterThan(this.extrapolatedPosition, 0),
586575
I18nManager.isRTL ? DIRECTION_RIGHT : DIRECTION_LEFT,
587576
I18nManager.isRTL ? DIRECTION_LEFT : DIRECTION_RIGHT
588577
)

0 commit comments

Comments
 (0)