mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Prevent intersectionRatio from being higher than 1 in IntersectionObserverEntry (#41448)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
11aadb7287
commit
5948ab7515
+5
-3
@@ -66,10 +66,12 @@ export default class IntersectionObserverEntry {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (
|
||||
const ratio =
|
||||
(intersectionRect.width * intersectionRect.height) /
|
||||
(boundingClientRect.width * boundingClientRect.height)
|
||||
);
|
||||
(boundingClientRect.width * boundingClientRect.height);
|
||||
|
||||
// Prevent rounding errors from making this value greater than 1.
|
||||
return Math.min(ratio, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user