Skip to content

Commit 5948ab7

Browse files
rubennortefacebook-github-bot
authored andcommitted
Prevent intersectionRatio from being higher than 1 in IntersectionObserverEntry (#41448)
Summary: Pull Request resolved: #41448 This was possible before due to precision problems with `double` (we were seeing values like 1.000000002). This is an easy way to prevent that problem. Changelog: [internal] Reviewed By: rshest Differential Revision: D51230183 fbshipit-source-id: 757ef181fe369d525831faf8a6d907467efc544c
1 parent 11aadb7 commit 5948ab7

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/react-native/Libraries/IntersectionObserver/IntersectionObserverEntry.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ export default class IntersectionObserverEntry {
6666
return 0;
6767
}
6868

69-
return (
69+
const ratio =
7070
(intersectionRect.width * intersectionRect.height) /
71-
(boundingClientRect.width * boundingClientRect.height)
72-
);
71+
(boundingClientRect.width * boundingClientRect.height);
72+
73+
// Prevent rounding errors from making this value greater than 1.
74+
return Math.min(ratio, 1);
7375
}
7476

7577
/**

0 commit comments

Comments
 (0)