Skip to content

Commit e12800b

Browse files
mdvaccafacebook-github-bot
authored andcommitted
Implement Legacy measure API on Fabric
Summary: This diff exposes the legacy measure() method on Fabric. This method will be replaced by getRelativeLayoutMetrics in the future, but we are exposing this in order to make Fabric migration easier. Reviewed By: JoshuaGross, shergin Differential Revision: D16432928 fbshipit-source-id: 25cc21fb48ec0749081f112af9230bfe53314d6b
1 parent a4a3618 commit e12800b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

ReactCommon/fabric/uimanager/UIManagerBinding.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,34 @@ jsi::Value UIManagerBinding::get(
421421
});
422422
}
423423

424+
if (methodName == "measure") {
425+
return jsi::Function::createFromHostFunction(
426+
runtime,
427+
name,
428+
2,
429+
[&uiManager](
430+
jsi::Runtime &runtime,
431+
const jsi::Value &thisValue,
432+
const jsi::Value *arguments,
433+
size_t count) -> jsi::Value {
434+
auto layoutMetrics = uiManager.getRelativeLayoutMetrics(
435+
*shadowNodeFromValue(runtime, arguments[0]), nullptr);
436+
auto frame = layoutMetrics.frame;
437+
auto onSuccessFunction =
438+
arguments[1].getObject(runtime).getFunction(runtime);
439+
440+
onSuccessFunction.call(
441+
runtime,
442+
{0,
443+
0,
444+
jsi::Value{runtime, (double)frame.origin.x},
445+
jsi::Value{runtime, (double)frame.origin.y},
446+
jsi::Value{runtime, (double)frame.size.width},
447+
jsi::Value{runtime, (double)frame.size.height}});
448+
return jsi::Value::undefined();
449+
});
450+
}
451+
424452
if (methodName == "measureInWindow") {
425453
return jsi::Function::createFromHostFunction(
426454
runtime,

0 commit comments

Comments
 (0)