From 69b8346dfd4200c50107cc2b8f75d2d97c1e7cdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?avery=20=E2=9C=BF?= Date: Sun, 17 Mar 2024 19:36:45 -0700 Subject: [PATCH] roundToNearestPixel in normalizeSnapPoint --- src/utilities/normalizeSnapPoint.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/utilities/normalizeSnapPoint.ts b/src/utilities/normalizeSnapPoint.ts index 46745dbf..a54d1297 100644 --- a/src/utilities/normalizeSnapPoint.ts +++ b/src/utilities/normalizeSnapPoint.ts @@ -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. */ @@ -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) + ); };