Skip to content

Commit 0a600fc

Browse files
committed
roundToNearestPixel in normalizeSnapPoint
1 parent 7f718ea commit 0a600fc

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/utilities/normalizeSnapPoint.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { roundToNearestPixel } from './roundToNearestPixel';
2+
13
/**
24
* Converts a snap point to fixed numbers.
35
*/
@@ -13,5 +15,8 @@ export const normalizeSnapPoint = (
1315
normalizedSnapPoint =
1416
(Number(normalizedSnapPoint.split('%')[0]) * containerHeight) / 100;
1517
}
16-
return Math.max(0, containerHeight - normalizedSnapPoint);
18+
return Math.max(
19+
0,
20+
roundToNearestPixel(containerHeight - normalizedSnapPoint)
21+
);
1722
};

src/utilities/roundToNearestPixel.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { PixelRatio } from 'react-native';
2+
3+
const PIXEL_DENSITY = PixelRatio.get();
4+
5+
export function roundToNearestPixel(position: number) {
6+
'worklet';
7+
return Math.round(position * PIXEL_DENSITY) / PIXEL_DENSITY;
8+
}

0 commit comments

Comments
 (0)