mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-29 04:45:19 +08:00
fix: spring was not triggered sometimes on tap (#67)
Co-Authored-By: Satyajit Sahoo <satyajit.happy@gmail.com>
This commit is contained in:
committed by
satyajit.happy
parent
3f64539cee
commit
8bbddb21bc
@@ -243,6 +243,8 @@ export default class DrawerView extends React.PureComponent<Props> {
|
|||||||
|
|
||||||
private isStatusBarHidden: boolean = false;
|
private isStatusBarHidden: boolean = false;
|
||||||
|
|
||||||
|
private isSpringManuallyTriggered = new Value<Binary>(FALSE);
|
||||||
|
|
||||||
private transitionTo = (isOpen: number | Animated.Node<number>) => {
|
private transitionTo = (isOpen: number | Animated.Node<number>) => {
|
||||||
const toValue = new Value(0);
|
const toValue = new Value(0);
|
||||||
const frameTime = new Value(0);
|
const frameTime = new Value(0);
|
||||||
@@ -347,6 +349,7 @@ export default class DrawerView extends React.PureComponent<Props> {
|
|||||||
cond(
|
cond(
|
||||||
eq(this.gestureState, State.ACTIVE),
|
eq(this.gestureState, State.ACTIVE),
|
||||||
[
|
[
|
||||||
|
set(this.isSpringManuallyTriggered, FALSE),
|
||||||
cond(this.isSwiping, NOOP, [
|
cond(this.isSwiping, NOOP, [
|
||||||
// We weren't dragging before, set it to true
|
// We weren't dragging before, set it to true
|
||||||
set(this.isSwiping, TRUE),
|
set(this.isSwiping, TRUE),
|
||||||
@@ -366,27 +369,31 @@ export default class DrawerView extends React.PureComponent<Props> {
|
|||||||
set(this.touchX, 0),
|
set(this.touchX, 0),
|
||||||
this.transitionTo(
|
this.transitionTo(
|
||||||
cond(
|
cond(
|
||||||
or(
|
this.isSpringManuallyTriggered,
|
||||||
and(
|
this.isOpen,
|
||||||
greaterThan(abs(this.gestureX), SWIPE_DISTANCE_MINIMUM),
|
|
||||||
greaterThan(abs(this.velocityX), this.swipeVelocityThreshold)
|
|
||||||
),
|
|
||||||
greaterThan(abs(this.gestureX), this.swipeDistanceThreshold)
|
|
||||||
),
|
|
||||||
cond(
|
cond(
|
||||||
eq(this.drawerPosition, DIRECTION_LEFT),
|
or(
|
||||||
// If swiped to right, open the drawer, otherwise close it
|
and(
|
||||||
greaterThan(
|
greaterThan(abs(this.gestureX), SWIPE_DISTANCE_MINIMUM),
|
||||||
cond(eq(this.velocityX, 0), this.gestureX, this.velocityX),
|
greaterThan(abs(this.velocityX), this.swipeVelocityThreshold)
|
||||||
0
|
),
|
||||||
|
greaterThan(abs(this.gestureX), this.swipeDistanceThreshold)
|
||||||
),
|
),
|
||||||
// If swiped to left, open the drawer, otherwise close it
|
cond(
|
||||||
lessThan(
|
eq(this.drawerPosition, DIRECTION_LEFT),
|
||||||
cond(eq(this.velocityX, 0), this.gestureX, this.velocityX),
|
// If swiped to right, open the drawer, otherwise close it
|
||||||
0
|
greaterThan(
|
||||||
)
|
cond(eq(this.velocityX, 0), this.gestureX, this.velocityX),
|
||||||
),
|
0
|
||||||
this.isOpen
|
),
|
||||||
|
// 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) => {
|
private toggleDrawer = (open: boolean) => {
|
||||||
this.nextIsOpen.setValue(open ? TRUE : FALSE);
|
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
|
// 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
|
// However, there's a race condition on Android, so we need to set a bit earlier
|
||||||
|
|||||||
Reference in New Issue
Block a user