Create synchronous method to get bounding client rect
Summary: Changelog: [internal] Added internal method in Fabric to synchronously get layout information Reviewed By: sammy-SC Differential Revision: D43080208 fbshipit-source-id: 8af9fe8ef9dbfe37c4b70101cc13e12905ee5b69
This commit is contained in:
Родитель
6018c19991
Коммит
97d90c66a8
|
@ -620,7 +620,7 @@ jsi::Value UIManagerBinding::get(
|
|||
*shadowNodeFromValue(runtime, arguments[0]),
|
||||
nullptr,
|
||||
{/* .includeTransform = */ true,
|
||||
/* includeViewportOffset = */ true});
|
||||
/* .includeViewportOffset = */ true});
|
||||
|
||||
auto onSuccessFunction =
|
||||
arguments[1].getObject(runtime).getFunction(runtime);
|
||||
|
@ -641,6 +641,40 @@ jsi::Value UIManagerBinding::get(
|
|||
});
|
||||
}
|
||||
|
||||
if (methodName == "getBoundingClientRect") {
|
||||
// This is similar to `measureInWindow`, except it's explicitly synchronous
|
||||
// (returns the result instead of passing it to a callback).
|
||||
// The behavior is similar to `Element.prototype.getBoundingClientRect` from
|
||||
// Web.
|
||||
return jsi::Function::createFromHostFunction(
|
||||
runtime,
|
||||
name,
|
||||
1,
|
||||
[uiManager](
|
||||
jsi::Runtime &runtime,
|
||||
jsi::Value const & /*thisValue*/,
|
||||
jsi::Value const *arguments,
|
||||
size_t /*count*/) noexcept -> jsi::Value {
|
||||
auto layoutMetrics = uiManager->getRelativeLayoutMetrics(
|
||||
*shadowNodeFromValue(runtime, arguments[0]),
|
||||
nullptr,
|
||||
{/* .includeTransform = */ true,
|
||||
/* .includeViewportOffset = */ true});
|
||||
|
||||
if (layoutMetrics == EmptyLayoutMetrics) {
|
||||
return jsi::Value::undefined();
|
||||
}
|
||||
|
||||
auto frame = layoutMetrics.frame;
|
||||
return jsi::Array::createWithElements(
|
||||
runtime,
|
||||
jsi::Value{runtime, (double)frame.origin.x},
|
||||
jsi::Value{runtime, (double)frame.origin.y},
|
||||
jsi::Value{runtime, (double)frame.size.width},
|
||||
jsi::Value{runtime, (double)frame.size.height});
|
||||
});
|
||||
}
|
||||
|
||||
if (methodName == "sendAccessibilityEvent") {
|
||||
return jsi::Function::createFromHostFunction(
|
||||
runtime,
|
||||
|
|
Загрузка…
Ссылка в новой задаче