Fix origin calculation in getRelativeLayoutMetrics

Summary:
# Problem
The issue is in implementation of `LayoutableShadowNode::getRelativeLayoutMetrics`.
If you have view tree (A has a child B), and you call `B.getRelativeLayoutMetrics(A)`, the expected result is B's origin within A. The implementation wasn't reflecting that, it was reflecting B's origin within A + A's origin within its parent.

# Fix
When iterating over ancestors of ShadowNode, the last ancestor should be skipped.
AncestorList is a list that starts with provided ancestor and ends with parent of `this`. To skip provided ancestor we iterate to `rend() - 1`.

# Why does it work in some cases?
This function is triggered from `UIManager.getRelativeLayoutMetrics` without `ancestorShadowNode` provided, we find the RootShadowNode, which has origin `{0, 0}`.

Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D19447900

fbshipit-source-id: 4a9606dc1fab3fecfb85d337b014188d80e5b355
This commit is contained in:
Samuel Susla
2020-01-20 01:31:22 -08:00
committed by Facebook Github Bot
parent 1e81b67701
commit 5b156f83fa
@@ -55,7 +55,10 @@ LayoutMetrics LayoutableShadowNode::getRelativeLayoutMetrics(
auto layoutMetrics = getLayoutMetrics();
for (auto it = ancestors.rbegin(); it != ancestors.rend(); ++it) {
// `AncestorList` starts from the given ancestor node and ends with the parent
// node. We iterate from parent node (reverse iteration) and stop before the
// given ancestor (rend() - 1).
for (auto it = ancestors.rbegin(); it != ancestors.rend() - 1; ++it) {
auto &currentShadowNode = it->first.get();
auto layoutableCurrentShadowNode =