Skip to content

Commit 69b8346

Browse files
committed
roundToNearestPixel in normalizeSnapPoint
1 parent fc1a76f commit 69b8346

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/utilities/normalizeSnapPoint.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
import { PixelRatio } from 'react-native';
2+
3+
const PIXEL_DENSITY = PixelRatio.get();
4+
5+
function roundToNearestPixel(position: number) {
6+
'worklet';
7+
return Math.round(position * PIXEL_DENSITY) / PIXEL_DENSITY;
8+
}
9+
110
/**
211
* Converts a snap point to fixed numbers.
312
*/
@@ -13,5 +22,8 @@ export const normalizeSnapPoint = (
1322
normalizedSnapPoint =
1423
(Number(normalizedSnapPoint.split('%')[0]) * containerHeight) / 100;
1524
}
16-
return Math.max(0, containerHeight - normalizedSnapPoint);
25+
return Math.max(
26+
0,
27+
roundToNearestPixel(containerHeight - normalizedSnapPoint)
28+
);
1729
};

0 commit comments

Comments
 (0)