[fix] NativeMethodsMixin measure/measureInWindow with scroll

Account for scroll offsets when calculating measurements.

Fix #702
Fix #805
Close #806
This commit is contained in:
Bulat Kidasov
2018-02-09 10:25:03 +04:00
committed by Nicolas Gallagher
parent 9ee89bc7f7
commit 399f465e59
+6 -4
View File
@@ -16,11 +16,13 @@ import setValueForStyles from '../../vendor/setValueForStyles';
const getRect = node => {
const height = node.offsetHeight;
const width = node.offsetWidth;
let left = 0;
let top = 0;
let left = node.offsetLeft;
let top = node.offsetTop;
node = node.offsetParent;
while (node && node.nodeType === 1 /* Node.ELEMENT_NODE */) {
left += node.offsetLeft;
top += node.offsetTop;
left += node.offsetLeft - node.scrollLeft;
top += node.offsetTop - node.scrollTop;
node = node.offsetParent;
}
return { height, left, top, width };