@@ -876,6 +876,265 @@ jsi::Value UIManagerBinding::get(
876876 });
877877 }
878878
879+ if (methodName == " measureInstance" ) {
880+ auto paramCount = 1 ;
881+ return jsi::Function::createFromHostFunction (
882+ runtime,
883+ name,
884+ paramCount,
885+ [uiManager, methodName, paramCount](
886+ jsi::Runtime& runtime,
887+ const jsi::Value& /* thisValue*/ ,
888+ const jsi::Value* arguments,
889+ size_t count) -> jsi::Value {
890+ validateArgumentCount (runtime, methodName, paramCount, count);
891+
892+ if (!arguments[0 ].isObject ()) {
893+ auto result = jsi::Object (runtime);
894+ result.setProperty (runtime, " x" , 0 );
895+ result.setProperty (runtime, " y" , 0 );
896+ result.setProperty (runtime, " width" , 0 );
897+ result.setProperty (runtime, " height" , 0 );
898+ return result;
899+ }
900+
901+ auto shadowNode = Bridging<std::shared_ptr<const ShadowNode>>::fromJs (
902+ runtime, arguments[0 ]);
903+
904+ auto currentRevision =
905+ uiManager->getShadowTreeRevisionProvider ()->getCurrentRevision (
906+ shadowNode->getSurfaceId ());
907+
908+ if (currentRevision == nullptr ) {
909+ auto result = jsi::Object (runtime);
910+ result.setProperty (runtime, " x" , 0 );
911+ result.setProperty (runtime, " y" , 0 );
912+ result.setProperty (runtime, " width" , 0 );
913+ result.setProperty (runtime, " height" , 0 );
914+ return result;
915+ }
916+
917+ auto domRect = dom::getBoundingClientRect (
918+ currentRevision, *shadowNode, true /* includeTransform */ );
919+
920+ auto result = jsi::Object (runtime);
921+ result.setProperty (runtime, " x" , domRect.x );
922+ result.setProperty (runtime, " y" , domRect.y );
923+ result.setProperty (runtime, " width" , domRect.width );
924+ result.setProperty (runtime, " height" , domRect.height );
925+
926+ auto * viewTransitionDelegate = uiManager->getViewTransitionDelegate ();
927+ if (viewTransitionDelegate != nullptr ) {
928+ viewTransitionDelegate->captureLayoutMetricsFromRoot (shadowNode);
929+ }
930+
931+ return result;
932+ });
933+ }
934+
935+ if (methodName == " applyViewTransitionName" ) {
936+ auto paramCount = 3 ;
937+ return jsi::Function::createFromHostFunction (
938+ runtime,
939+ name,
940+ paramCount,
941+ [uiManager, methodName, paramCount](
942+ jsi::Runtime& runtime,
943+ const jsi::Value& /* thisValue*/ ,
944+ const jsi::Value* arguments,
945+ size_t count) -> jsi::Value {
946+ validateArgumentCount (runtime, methodName, paramCount, count);
947+
948+ if (arguments[0 ].isObject ()) {
949+ auto shadowNode =
950+ Bridging<std::shared_ptr<const ShadowNode>>::fromJs (
951+ runtime, arguments[0 ]);
952+ auto transitionName = arguments[1 ].isString ()
953+ ? stringFromValue (runtime, arguments[1 ])
954+ : " " ;
955+ auto className = arguments[2 ].isString ()
956+ ? stringFromValue (runtime, arguments[2 ])
957+ : " " ;
958+ if (!transitionName.empty ()) {
959+ auto * viewTransitionDelegate =
960+ uiManager->getViewTransitionDelegate ();
961+ if (viewTransitionDelegate != nullptr ) {
962+ viewTransitionDelegate->applyViewTransitionName (
963+ shadowNode, transitionName, className);
964+ }
965+ }
966+ }
967+
968+ return jsi::Value::undefined ();
969+ });
970+ }
971+
972+ if (methodName == " cancelViewTransitionName" ) {
973+ auto paramCount = 2 ;
974+ return jsi::Function::createFromHostFunction (
975+ runtime,
976+ name,
977+ paramCount,
978+ [uiManager, methodName, paramCount](
979+ jsi::Runtime& runtime,
980+ const jsi::Value& /* thisValue*/ ,
981+ const jsi::Value* arguments,
982+ size_t count) -> jsi::Value {
983+ validateArgumentCount (runtime, methodName, paramCount, count);
984+
985+ if (arguments[0 ].isObject ()) {
986+ auto shadowNode =
987+ Bridging<std::shared_ptr<const ShadowNode>>::fromJs (
988+ runtime, arguments[0 ]);
989+ auto transitionName = arguments[1 ].isString ()
990+ ? stringFromValue (runtime, arguments[1 ])
991+ : " " ;
992+ if (!transitionName.empty ()) {
993+ auto * viewTransitionDelegate =
994+ uiManager->getViewTransitionDelegate ();
995+ if (viewTransitionDelegate != nullptr ) {
996+ viewTransitionDelegate->cancelViewTransitionName (
997+ shadowNode, transitionName);
998+ }
999+ }
1000+ }
1001+
1002+ return jsi::Value::undefined ();
1003+ });
1004+ }
1005+
1006+ if (methodName == " restoreViewTransitionName" ) {
1007+ auto paramCount = 1 ;
1008+ return jsi::Function::createFromHostFunction (
1009+ runtime,
1010+ name,
1011+ paramCount,
1012+ [uiManager, methodName, paramCount](
1013+ jsi::Runtime& runtime,
1014+ const jsi::Value& /* thisValue*/ ,
1015+ const jsi::Value* arguments,
1016+ size_t count) -> jsi::Value {
1017+ validateArgumentCount (runtime, methodName, paramCount, count);
1018+
1019+ if (arguments[0 ].isObject ()) {
1020+ auto shadowNode =
1021+ Bridging<std::shared_ptr<const ShadowNode>>::fromJs (
1022+ runtime, arguments[0 ]);
1023+ auto * viewTransitionDelegate =
1024+ uiManager->getViewTransitionDelegate ();
1025+ if (viewTransitionDelegate != nullptr ) {
1026+ viewTransitionDelegate->restoreViewTransitionName (shadowNode);
1027+ }
1028+ }
1029+
1030+ return jsi::Value::undefined ();
1031+ });
1032+ }
1033+
1034+ if (methodName == " startViewTransition" ) {
1035+ auto paramCount = 1 ;
1036+ return jsi::Function::createFromHostFunction (
1037+ runtime,
1038+ name,
1039+ paramCount,
1040+ [uiManager, methodName, paramCount](
1041+ jsi::Runtime& runtime,
1042+ const jsi::Value& /* thisValue*/ ,
1043+ const jsi::Value* arguments,
1044+ size_t count) -> jsi::Value {
1045+ validateArgumentCount (runtime, methodName, paramCount, count);
1046+
1047+ auto * viewTransitionDelegate = uiManager->getViewTransitionDelegate ();
1048+ if (viewTransitionDelegate == nullptr ) {
1049+ return jsi::Value::undefined ();
1050+ }
1051+
1052+ auto promiseConstructor =
1053+ runtime.global ().getPropertyAsFunction (runtime, " Promise" );
1054+
1055+ auto readyResolveFunc =
1056+ std::make_shared<std::shared_ptr<jsi::Function>>();
1057+ auto finishedResolveFunc =
1058+ std::make_shared<std::shared_ptr<jsi::Function>>();
1059+
1060+ auto mutationFunc = std::make_shared<jsi::Function>(
1061+ arguments[0 ].asObject (runtime).asFunction (runtime));
1062+
1063+ auto readyPromise = promiseConstructor.callAsConstructor (
1064+ runtime,
1065+ jsi::Function::createFromHostFunction (
1066+ runtime,
1067+ jsi::PropNameID::forAscii (runtime, " readyExecutor" ),
1068+ 2 ,
1069+ [readyResolveFunc](
1070+ jsi::Runtime& runtime,
1071+ const jsi::Value& /* thisValue*/ ,
1072+ const jsi::Value* args,
1073+ size_t /* count*/ ) -> jsi::Value {
1074+ auto onReadyFunc = std::make_shared<jsi::Function>(
1075+ args[0 ].asObject (runtime).asFunction (runtime));
1076+ *readyResolveFunc = onReadyFunc;
1077+ return jsi::Value::undefined ();
1078+ }));
1079+
1080+ auto finishedPromise = promiseConstructor.callAsConstructor (
1081+ runtime,
1082+ jsi::Function::createFromHostFunction (
1083+ runtime,
1084+ jsi::PropNameID::forAscii (runtime, " finishedExecutor" ),
1085+ 2 ,
1086+ [finishedResolveFunc, viewTransitionDelegate](
1087+ jsi::Runtime& rt,
1088+ const jsi::Value& /* thisValue*/ ,
1089+ const jsi::Value* args,
1090+ size_t /* count*/ ) -> jsi::Value {
1091+ auto onCompleteFunc = std::make_shared<jsi::Function>(
1092+ args[0 ].asObject (rt).asFunction (rt));
1093+ *finishedResolveFunc = std::make_shared<jsi::Function>(
1094+ jsi::Function::createFromHostFunction (
1095+ rt,
1096+ jsi::PropNameID::forAscii (rt, " finishedResolve" ),
1097+ 0 ,
1098+ [onCompleteFunc, viewTransitionDelegate](
1099+ jsi::Runtime& runtime,
1100+ const jsi::Value& /* thisValue*/ ,
1101+ const jsi::Value* /* args*/ ,
1102+ size_t /* count*/ ) -> jsi::Value {
1103+ onCompleteFunc->call (runtime);
1104+ viewTransitionDelegate->startViewTransitionEnd ();
1105+ return jsi::Value::undefined ();
1106+ }));
1107+ return jsi::Value::undefined ();
1108+ }));
1109+
1110+ auto result = jsi::Object (runtime);
1111+ result.setProperty (runtime, " ready" , std::move (readyPromise));
1112+ result.setProperty (runtime, " finished" , std::move (finishedPromise));
1113+
1114+ viewTransitionDelegate->startViewTransition (
1115+ [&runtime, mutationFunc = std::move (mutationFunc)]() {
1116+ mutationFunc->call (runtime);
1117+ },
1118+ [readyResolveFunc = std::move (readyResolveFunc), &runtime]() {
1119+ if (*readyResolveFunc) {
1120+ (*readyResolveFunc)->call (runtime);
1121+ }
1122+ },
1123+ [finishedResolveFunc = std::move (finishedResolveFunc),
1124+ uiManager]() {
1125+ uiManager->runtimeExecutor_ (
1126+ [finishedResolveFunc = std::move (finishedResolveFunc)](
1127+ jsi::Runtime& rt) mutable {
1128+ if (*finishedResolveFunc) {
1129+ (*finishedResolveFunc)->call (rt);
1130+ }
1131+ });
1132+ });
1133+
1134+ return jsi::Value (runtime, result);
1135+ });
1136+ }
1137+
8791138 return jsi::Value::undefined ();
8801139}
8811140
0 commit comments