Skip to content

Commit

Permalink
fix: spring was not triggered sometimes on tap (facebook#67)
Browse files Browse the repository at this point in the history
Co-Authored-By: Satyajit Sahoo <satyajit.happy@gmail.com>
  • Loading branch information
osdnk and satya164 committed Aug 18, 2019
1 parent 3f64539 commit 8bbddb2
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions packages/drawer/src/views/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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),
Expand All @@ -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)
),
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
)
),
// If swiped to left, open the drawer, otherwise close it
lessThan(
cond(eq(this.velocityX, 0), this.gestureX, this.velocityX),
0
)
),
this.isOpen
this.isOpen
)
)
),
]
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8bbddb2

Please sign in to comment.