fix: spring was not triggered sometimes on tap (#67)

Co-Authored-By: Satyajit Sahoo <satyajit.happy@gmail.com>
This commit is contained in:
Michał Osadnik
2019-05-13 16:46:47 +02:00
committed by satyajit.happy
parent 3f64539cee
commit 8bbddb21bc

View File

@@ -243,6 +243,8 @@ export default class DrawerView extends React.PureComponent<Props> {
private isStatusBarHidden: boolean = false;
private isSpringManuallyTriggered = new Value<Binary>(FALSE);
private transitionTo = (isOpen: number | Animated.Node<number>) => {
const toValue = new Value(0);
const frameTime = new Value(0);
@@ -347,6 +349,7 @@ export default class DrawerView extends React.PureComponent<Props> {
cond(
eq(this.gestureState, State.ACTIVE),
[
set(this.isSpringManuallyTriggered, FALSE),
cond(this.isSwiping, NOOP, [
// We weren't dragging before, set it to true
set(this.isSwiping, TRUE),
@@ -366,27 +369,31 @@ export default class DrawerView extends React.PureComponent<Props> {
set(this.touchX, 0),
this.transitionTo(
cond(
or(
and(
greaterThan(abs(this.gestureX), SWIPE_DISTANCE_MINIMUM),
greaterThan(abs(this.velocityX), this.swipeVelocityThreshold)
),
greaterThan(abs(this.gestureX), this.swipeDistanceThreshold)
),
this.isSpringManuallyTriggered,
this.isOpen,
cond(
eq(this.drawerPosition, DIRECTION_LEFT),
// If swiped to right, open the drawer, otherwise close it
greaterThan(
cond(eq(this.velocityX, 0), this.gestureX, this.velocityX),
0
or(
and(
greaterThan(abs(this.gestureX), SWIPE_DISTANCE_MINIMUM),
greaterThan(abs(this.velocityX), this.swipeVelocityThreshold)
),
greaterThan(abs(this.gestureX), this.swipeDistanceThreshold)
),
// If swiped to left, open the drawer, otherwise close it
lessThan(
cond(eq(this.velocityX, 0), this.gestureX, this.velocityX),
0
)
),
this.isOpen
cond(
eq(this.drawerPosition, DIRECTION_LEFT),
// If swiped to right, open the drawer, otherwise close it
greaterThan(
cond(eq(this.velocityX, 0), this.gestureX, this.velocityX),
0
),
// If swiped to left, open the drawer, otherwise close it
lessThan(
cond(eq(this.velocityX, 0), this.gestureX, this.velocityX),
0
)
),
this.isOpen
)
)
),
]
@@ -441,6 +448,7 @@ export default class DrawerView extends React.PureComponent<Props> {
private toggleDrawer = (open: boolean) => {
this.nextIsOpen.setValue(open ? TRUE : FALSE);
this.isSpringManuallyTriggered.setValue(TRUE);
// This value will also be set shortly after as changing this.nextIsOpen changes this.isOpen
// However, there's a race condition on Android, so we need to set a bit earlier