Skip to content

Commit

Permalink
fix: Add constraints for velocity in goBackGesture screen transition (
Browse files Browse the repository at this point in the history
#2061)

## Description

Without this constraint, especially on the simulator, `event.velocity`
sometimes has a huge value. This can lead to unintended behavior where
even a slight movement can trigger a transition back to the previous
screen instead of canceling it.

## Checklist

- [x] Ensured that CI passes
  • Loading branch information
piaskowyk authored and tboba committed Mar 25, 2024
1 parent 4f61e7c commit d031d1a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/gesture-handler/ScreenGestureDetector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,10 @@ const ScreenGestureDetector = ({

const velocityFactor = 0.3;
const screenSize = screenTransitionConfig.value.screenDimensions;
const distanceX = event.translationX + event.velocityX * velocityFactor;
const distanceY = event.translationY + event.velocityY * velocityFactor;
const distanceX =
event.translationX + Math.min(event.velocityX * velocityFactor, 100);
const distanceY =
event.translationY + Math.min(event.velocityY * velocityFactor, 100);
const requiredXDistance = screenSize.width / 2;
const requiredYDistance = screenSize.height / 2;
const isTransitionCanceled = checkIfTransitionCancelled(
Expand Down

0 comments on commit d031d1a

Please sign in to comment.