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
software-mansion#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 ja1ns committed Oct 9, 2024
1 parent e72b06d commit f1dd986
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 f1dd986

Please sign in to comment.