Skip to content

Commit 8bbddb2

Browse files
osdnksatya164
andcommitted
fix: spring was not triggered sometimes on tap (facebook#67)
Co-Authored-By: Satyajit Sahoo <[email protected]>
1 parent 3f64539 commit 8bbddb2

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

packages/drawer/src/views/Drawer.tsx

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ export default class DrawerView extends React.PureComponent<Props> {
243243

244244
private isStatusBarHidden: boolean = false;
245245

246+
private isSpringManuallyTriggered = new Value<Binary>(FALSE);
247+
246248
private transitionTo = (isOpen: number | Animated.Node<number>) => {
247249
const toValue = new Value(0);
248250
const frameTime = new Value(0);
@@ -347,6 +349,7 @@ export default class DrawerView extends React.PureComponent<Props> {
347349
cond(
348350
eq(this.gestureState, State.ACTIVE),
349351
[
352+
set(this.isSpringManuallyTriggered, FALSE),
350353
cond(this.isSwiping, NOOP, [
351354
// We weren't dragging before, set it to true
352355
set(this.isSwiping, TRUE),
@@ -366,27 +369,31 @@ export default class DrawerView extends React.PureComponent<Props> {
366369
set(this.touchX, 0),
367370
this.transitionTo(
368371
cond(
369-
or(
370-
and(
371-
greaterThan(abs(this.gestureX), SWIPE_DISTANCE_MINIMUM),
372-
greaterThan(abs(this.velocityX), this.swipeVelocityThreshold)
373-
),
374-
greaterThan(abs(this.gestureX), this.swipeDistanceThreshold)
375-
),
372+
this.isSpringManuallyTriggered,
373+
this.isOpen,
376374
cond(
377-
eq(this.drawerPosition, DIRECTION_LEFT),
378-
// If swiped to right, open the drawer, otherwise close it
379-
greaterThan(
380-
cond(eq(this.velocityX, 0), this.gestureX, this.velocityX),
381-
0
375+
or(
376+
and(
377+
greaterThan(abs(this.gestureX), SWIPE_DISTANCE_MINIMUM),
378+
greaterThan(abs(this.velocityX), this.swipeVelocityThreshold)
379+
),
380+
greaterThan(abs(this.gestureX), this.swipeDistanceThreshold)
381+
),
382+
cond(
383+
eq(this.drawerPosition, DIRECTION_LEFT),
384+
// If swiped to right, open the drawer, otherwise close it
385+
greaterThan(
386+
cond(eq(this.velocityX, 0), this.gestureX, this.velocityX),
387+
0
388+
),
389+
// If swiped to left, open the drawer, otherwise close it
390+
lessThan(
391+
cond(eq(this.velocityX, 0), this.gestureX, this.velocityX),
392+
0
393+
)
382394
),
383-
// If swiped to left, open the drawer, otherwise close it
384-
lessThan(
385-
cond(eq(this.velocityX, 0), this.gestureX, this.velocityX),
386-
0
387-
)
388-
),
389-
this.isOpen
395+
this.isOpen
396+
)
390397
)
391398
),
392399
]
@@ -441,6 +448,7 @@ export default class DrawerView extends React.PureComponent<Props> {
441448

442449
private toggleDrawer = (open: boolean) => {
443450
this.nextIsOpen.setValue(open ? TRUE : FALSE);
451+
this.isSpringManuallyTriggered.setValue(TRUE);
444452

445453
// This value will also be set shortly after as changing this.nextIsOpen changes this.isOpen
446454
// However, there's a race condition on Android, so we need to set a bit earlier

0 commit comments

Comments
 (0)