From adbfedcd58d4e3d358c6c9691710bb8e4e0d8afb Mon Sep 17 00:00:00 2001 From: Tien Pham Date: Fri, 20 Mar 2020 03:55:03 +0700 Subject: [PATCH] fix: use the correct velocity value in closing animation (#7836) In this commit https://github.com/react-navigation/react-navigation/commit/f24d3a3461ee8a566c25ce7d13f31035b4be2691 we modified the `velocity` in inverted gesture, but since we also use this value in the closing animation, the change in that commit also introduced a new bug: ![Mar-20-2020 03-40-05](https://user-images.githubusercontent.com/57227217/77113229-006f0500-6a5d-11ea-97b5-571e8301cd87.gif) This PR fixes the issue by keeping the original velocity value. --- packages/stack/src/views/Stack/Card.tsx | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/stack/src/views/Stack/Card.tsx b/packages/stack/src/views/Stack/Card.tsx index d3a50929..30ca870e 100755 --- a/packages/stack/src/views/Stack/Card.tsx +++ b/packages/stack/src/views/Stack/Card.tsx @@ -271,16 +271,15 @@ export default class Card extends React.Component { velocity = nativeEvent.velocityX; } - if ( - gestureDirection === 'horizontal-inverted' || - gestureDirection === 'vertical-inverted' - ) { - translation *= -1; - velocity *= -1; - } + const gestureDirectionFactor = + gestureDirection === 'horizontal' || gestureDirection === 'vertical' + ? 1 + : -1; const closing = - translation + velocity * gestureVelocityImpact > distance / 2 + gestureDirectionFactor * + (translation + velocity * gestureVelocityImpact) > + distance / 2 ? velocity !== 0 || translation !== 0 : false;