Skip to content

Commit

Permalink
fix: calculate snap points based on screen size
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillzyusko committed Feb 21, 2024
1 parent 0293460 commit 20f51ca
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/components/MultiGestureCanvas/usePanGesture.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-param-reassign */
import {Dimensions} from 'react-native';
import type {PanGesture} from 'react-native-gesture-handler';
import {Gesture} from 'react-native-gesture-handler';
import {runOnJS, useDerivedValue, useSharedValue, useWorkletCallback, withDecay, withSpring} from 'react-native-reanimated';
Expand All @@ -10,6 +11,9 @@ import * as MultiGestureCanvasUtils from './utils';
// We're using a "withDecay" animation to smoothly phase out the pan animation
// https://docs.swmansion.com/react-native-reanimated/docs/animations/withDecay/
const PAN_DECAY_DECELARATION = 0.9915;
const SCREEN_HEIGHT = Dimensions.get('screen').height;
const SNAP_POINT = SCREEN_HEIGHT / 4;
const SNAP_POINT_HIDDEN = SCREEN_HEIGHT / 1.2;

type UsePanGestureProps = Pick<
MultiGestureCanvasVariables,
Expand Down Expand Up @@ -134,9 +138,8 @@ const usePanGesture = ({
} else {
const finalTranslateY = offsetY.value + panVelocityY.value * 0.2;

// TODO: calculate these values (250/500) programmatically
if (finalTranslateY > 250 && zoomScale.value <= 1) {
offsetY.value = withSpring(500, SPRING_CONFIG, () => {
if (finalTranslateY > SNAP_POINT && zoomScale.value <= 1) {
offsetY.value = withSpring(SNAP_POINT_HIDDEN, SPRING_CONFIG, () => {
isSwipingDownToClose.value = false;
});

Expand Down

0 comments on commit 20f51ca

Please sign in to comment.