From b7937373934cb5ede2ea536483b43ee17fdda68a Mon Sep 17 00:00:00 2001 From: Matthias Le Brun Date: Wed, 1 Feb 2017 10:56:51 +0100 Subject: [PATCH] [fix] onLayout calculation The 0.0.69 release introduced a regression in UIManager's measurement calculations. Using `offset` properties returns the offset relative to the closest positioned ancestor. Make `getRect` iterate over the ancestor chain. Fix #341 Close #345 --- src/apis/UIManager/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/apis/UIManager/index.js b/src/apis/UIManager/index.js index 6622cdef..2a397d89 100644 --- a/src/apis/UIManager/index.js +++ b/src/apis/UIManager/index.js @@ -3,9 +3,14 @@ import CSSPropertyOperations from 'react-dom/lib/CSSPropertyOperations'; const getRect = (node) => { const height = node.offsetHeight; - const left = node.offsetLeft; - const top = node.offsetTop; const width = node.offsetWidth; + let left = 0; + let top = 0; + while (node && node.nodeType === 1 /* Node.ELEMENT_NODE */) { + left += node.offsetLeft; + top += node.offsetTop; + node = node.offsetParent; + } return { height, left, top, width }; };