Skip to content

Commit

Permalink
roundToNearestPixel in normalizeSnapPoint
Browse files Browse the repository at this point in the history
  • Loading branch information
yayvery committed Mar 18, 2024
1 parent fc1a76f commit 69b8346
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/utilities/normalizeSnapPoint.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import { PixelRatio } from 'react-native';

const PIXEL_DENSITY = PixelRatio.get();

function roundToNearestPixel(position: number) {
'worklet';
return Math.round(position * PIXEL_DENSITY) / PIXEL_DENSITY;
}

/**
* Converts a snap point to fixed numbers.
*/
Expand All @@ -13,5 +22,8 @@ export const normalizeSnapPoint = (
normalizedSnapPoint =
(Number(normalizedSnapPoint.split('%')[0]) * containerHeight) / 100;
}
return Math.max(0, containerHeight - normalizedSnapPoint);
return Math.max(
0,
roundToNearestPixel(containerHeight - normalizedSnapPoint)
);
};

0 comments on commit 69b8346

Please sign in to comment.