From d594d5a4e5b446d7e80e246d0b48fcb1a0d9679b Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Tue, 27 Nov 2018 18:01:01 -0800 Subject: [PATCH] Fabric: `UIManagerBinding::getRelativeLayoutMetrics` Summary: Exposing the getRelativeLayoutMetrics method to JS. Reviewed By: mdvacca Differential Revision: D13036552 fbshipit-source-id: de825dfde8e64163168510aea1eda77370753b29 --- .../fabric/uimanager/UIManagerBinding.cpp | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/ReactCommon/fabric/uimanager/UIManagerBinding.cpp b/ReactCommon/fabric/uimanager/UIManagerBinding.cpp index 6c460e973..c26f3b20e 100644 --- a/ReactCommon/fabric/uimanager/UIManagerBinding.cpp +++ b/ReactCommon/fabric/uimanager/UIManagerBinding.cpp @@ -281,6 +281,29 @@ jsi::Value UIManagerBinding::get( }); } + if (methodName == "getRelativeLayoutMetrics") { + return jsi::Function::createFromHostFunction( + runtime, + name, + 2, + [&uiManager]( + jsi::Runtime &runtime, + const jsi::Value &thisValue, + const jsi::Value *arguments, + size_t count) -> jsi::Value { + auto layoutMetrics = uiManager.getRelativeLayoutMetrics( + *shadowNodeFromValue(runtime, arguments[0]), + shadowNodeFromValue(runtime, arguments[1]).get()); + auto frame = layoutMetrics.frame; + auto result = jsi::Object(runtime); + result.setProperty(runtime, "left", frame.origin.x); + result.setProperty(runtime, "top", frame.origin.y); + result.setProperty(runtime, "width", frame.size.width); + result.setProperty(runtime, "height", frame.size.height); + return result; + }); + } + return jsi::Value::undefined(); }