From 8bbddb21bc49375bc1caaa614d4a7b2cd053571a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Osadnik?= Date: Mon, 13 May 2019 16:46:47 +0200 Subject: [PATCH] fix: spring was not triggered sometimes on tap (#67) Co-Authored-By: Satyajit Sahoo --- packages/drawer/src/views/Drawer.tsx | 46 ++++++++++++++++------------ 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/packages/drawer/src/views/Drawer.tsx b/packages/drawer/src/views/Drawer.tsx index 4e28acf8..f69eed87 100644 --- a/packages/drawer/src/views/Drawer.tsx +++ b/packages/drawer/src/views/Drawer.tsx @@ -243,6 +243,8 @@ export default class DrawerView extends React.PureComponent { private isStatusBarHidden: boolean = false; + private isSpringManuallyTriggered = new Value(FALSE); + private transitionTo = (isOpen: number | Animated.Node) => { const toValue = new Value(0); const frameTime = new Value(0); @@ -347,6 +349,7 @@ export default class DrawerView extends React.PureComponent { 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 { 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 { 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