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 15, 2024
1 parent a911c22 commit 44e7a05
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/utilities/normalizeSnapPoint.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { roundToNearestPixel } from './roundToNearestPixel';

/**
* Converts a snap point to fixed numbers.
*/
Expand All @@ -13,5 +15,8 @@ export const normalizeSnapPoint = (
normalizedSnapPoint =
(Number(normalizedSnapPoint.split('%')[0]) * containerHeight) / 100;
}
return Math.max(0, containerHeight - normalizedSnapPoint);
return Math.max(
0,
roundToNearestPixel(containerHeight - normalizedSnapPoint)
);
};
8 changes: 8 additions & 0 deletions src/utilities/roundToNearestPixel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { PixelRatio } from 'react-native';

const PIXEL_DENSITY = PixelRatio.get();

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

0 comments on commit 44e7a05

Please sign in to comment.