66 */
77
88#include " NativeDOM.h"
9+ #include < react/renderer/bridging/bridging.h>
910#include < react/renderer/components/root/RootShadowNode.h>
1011#include < react/renderer/dom/DOM.h>
1112#include < react/renderer/uimanager/PointerEventsProcessor.h>
1213#include < react/renderer/uimanager/UIManagerBinding.h>
13- #include < react/renderer/uimanager/primitives.h>
1414
1515#ifdef RN_DISABLE_OSS_PLUGIN_HEADER
1616#include " Plugins.h"
@@ -23,6 +23,14 @@ std::shared_ptr<facebook::react::TurboModule> NativeDOMModuleProvider(
2323
2424namespace facebook ::react {
2525
26+ namespace {
27+ inline ShadowNode::Shared getShadowNode (
28+ facebook::jsi::Runtime& runtime,
29+ jsi::Value& shadowNodeValue) {
30+ return Bridging<ShadowNode::Shared>::fromJs (runtime, shadowNodeValue);
31+ }
32+ } // namespace
33+
2634#pragma mark - Private helpers
2735
2836static UIManager& getUIManagerFromRuntime (facebook::jsi::Runtime& runtime) {
@@ -46,8 +54,7 @@ static RootShadowNode::Shared getCurrentShadowTreeRevision(
4654 }
4755
4856 return getCurrentShadowTreeRevision (
49- runtime,
50- shadowNodeFromValue (runtime, nativeNodeReference)->getSurfaceId ());
57+ runtime, getShadowNode (runtime, nativeNodeReference)->getSurfaceId ());
5158}
5259
5360static facebook::react::PointerEventsProcessor&
@@ -107,7 +114,7 @@ double NativeDOM::compareDocumentPosition(
107114 // Only the first is a document
108115 auto surfaceId = nativeNodeReference.asNumber ();
109116 shadowNode = currentRevision;
110- otherShadowNode = shadowNodeFromValue (rt, otherNativeNodeReference);
117+ otherShadowNode = getShadowNode (rt, otherNativeNodeReference);
111118
112119 if (isRootShadowNode (*otherShadowNode)) {
113120 // If the other is a root node, we just need to check if it is its
@@ -123,7 +130,7 @@ double NativeDOM::compareDocumentPosition(
123130 } else {
124131 // Only the second is a document
125132 auto otherSurfaceId = otherNativeNodeReference.asNumber ();
126- shadowNode = shadowNodeFromValue (rt, nativeNodeReference);
133+ shadowNode = getShadowNode (rt, nativeNodeReference);
127134 otherShadowNode = getCurrentShadowTreeRevision (rt, otherSurfaceId);
128135
129136 if (isRootShadowNode (*shadowNode)) {
@@ -138,8 +145,8 @@ double NativeDOM::compareDocumentPosition(
138145 }
139146 }
140147 } else {
141- shadowNode = shadowNodeFromValue (rt, nativeNodeReference);
142- otherShadowNode = shadowNodeFromValue (rt, otherNativeNodeReference);
148+ shadowNode = getShadowNode (rt, nativeNodeReference);
149+ otherShadowNode = getShadowNode (rt, otherNativeNodeReference);
143150 }
144151
145152 return dom::compareDocumentPosition (
@@ -160,7 +167,7 @@ std::vector<jsi::Value> NativeDOM::getChildNodes(
160167 }
161168
162169 auto childNodes = dom::getChildNodes (
163- currentRevision, *shadowNodeFromValue (rt, nativeNodeReference));
170+ currentRevision, *getShadowNode (rt, nativeNodeReference));
164171 return getArrayOfInstanceHandlesFromShadowNodes (childNodes, rt);
165172}
166173
@@ -172,7 +179,7 @@ jsi::Value NativeDOM::getParentNode(
172179 return jsi::Value::undefined ();
173180 }
174181
175- auto shadowNode = shadowNodeFromValue (rt, nativeNodeReference);
182+ auto shadowNode = getShadowNode (rt, nativeNodeReference);
176183 if (isRootShadowNode (*shadowNode)) {
177184 // The parent of the root node is the document.
178185 return jsi::Value{shadowNode->getSurfaceId ()};
@@ -203,7 +210,7 @@ bool NativeDOM::isConnected(jsi::Runtime& rt, jsi::Value nativeNodeReference) {
203210 return true ;
204211 }
205212
206- auto shadowNode = shadowNodeFromValue (rt, nativeNodeReference);
213+ auto shadowNode = getShadowNode (rt, nativeNodeReference);
207214 return dom::isConnected (currentRevision, *shadowNode);
208215}
209216
@@ -214,8 +221,7 @@ std::tuple<
214221 /* rightWidth: */ int ,
215222 /* bottomWidth: */ int ,
216223 /* leftWidth: */ int >
217- NativeDOM::getBorderWidth (jsi::Runtime& rt, jsi::Value nativeElementReference) {
218- auto shadowNode = shadowNodeFromValue (rt, nativeElementReference);
224+ NativeDOM::getBorderWidth (jsi::Runtime& rt, ShadowNode::Shared shadowNode) {
219225 auto currentRevision =
220226 getCurrentShadowTreeRevision (rt, shadowNode->getSurfaceId ());
221227 if (currentRevision == nullptr ) {
@@ -234,9 +240,8 @@ std::tuple<
234240 /* height: */ double >
235241NativeDOM::getBoundingClientRect (
236242 jsi::Runtime& rt,
237- jsi::Value nativeElementReference ,
243+ ShadowNode::Shared shadowNode ,
238244 bool includeTransform) {
239- auto shadowNode = shadowNodeFromValue (rt, nativeElementReference);
240245 auto currentRevision =
241246 getCurrentShadowTreeRevision (rt, shadowNode->getSurfaceId ());
242247 if (currentRevision == nullptr ) {
@@ -251,8 +256,7 @@ NativeDOM::getBoundingClientRect(
251256
252257std::tuple</* width: */ int , /* height: */ int > NativeDOM::getInnerSize (
253258 jsi::Runtime& rt,
254- jsi::Value nativeElementReference) {
255- auto shadowNode = shadowNodeFromValue (rt, nativeElementReference);
259+ ShadowNode::Shared shadowNode) {
256260 auto currentRevision =
257261 getCurrentShadowTreeRevision (rt, shadowNode->getSurfaceId ());
258262 if (currentRevision == nullptr ) {
@@ -264,10 +268,7 @@ std::tuple</* width: */ int, /* height: */ int> NativeDOM::getInnerSize(
264268}
265269
266270std::tuple</* scrollLeft: */ double , /* scrollTop: */ double >
267- NativeDOM::getScrollPosition (
268- jsi::Runtime& rt,
269- jsi::Value nativeElementReference) {
270- auto shadowNode = shadowNodeFromValue (rt, nativeElementReference);
271+ NativeDOM::getScrollPosition (jsi::Runtime& rt, ShadowNode::Shared shadowNode) {
271272 auto currentRevision =
272273 getCurrentShadowTreeRevision (rt, shadowNode->getSurfaceId ());
273274 if (currentRevision == nullptr ) {
@@ -279,8 +280,7 @@ NativeDOM::getScrollPosition(
279280}
280281
281282std::tuple</* scrollWidth: */ int , /* scrollHeight */ int >
282- NativeDOM::getScrollSize (jsi::Runtime& rt, jsi::Value nativeElementReference) {
283- auto shadowNode = shadowNodeFromValue (rt, nativeElementReference);
283+ NativeDOM::getScrollSize (jsi::Runtime& rt, ShadowNode::Shared shadowNode) {
284284 auto currentRevision =
285285 getCurrentShadowTreeRevision (rt, shadowNode->getSurfaceId ());
286286 if (currentRevision == nullptr ) {
@@ -293,15 +293,13 @@ NativeDOM::getScrollSize(jsi::Runtime& rt, jsi::Value nativeElementReference) {
293293
294294std::string NativeDOM::getTagName (
295295 jsi::Runtime& rt,
296- jsi::Value nativeElementReference) {
297- auto shadowNode = shadowNodeFromValue (rt, nativeElementReference);
296+ ShadowNode::Shared shadowNode) {
298297 return dom::getTagName (*shadowNode);
299298}
300299
301300std::string NativeDOM::getTextContent (
302301 jsi::Runtime& rt,
303- jsi::Value nativeNodeReference) {
304- auto shadowNode = shadowNodeFromValue (rt, nativeNodeReference);
302+ ShadowNode::Shared shadowNode) {
305303 auto currentRevision =
306304 getCurrentShadowTreeRevision (rt, shadowNode->getSurfaceId ());
307305 if (currentRevision == nullptr ) {
@@ -313,30 +311,27 @@ std::string NativeDOM::getTextContent(
313311
314312bool NativeDOM::hasPointerCapture (
315313 jsi::Runtime& rt,
316- jsi::Value nativeElementReference ,
314+ ShadowNode::Shared shadowNode ,
317315 double pointerId) {
318316 bool isCapturing = getPointerEventsProcessorFromRuntime (rt).hasPointerCapture (
319- static_cast <PointerIdentifier>(pointerId),
320- shadowNodeFromValue (rt, nativeElementReference).get ());
317+ static_cast <PointerIdentifier>(pointerId), shadowNode.get ());
321318 return isCapturing;
322319}
323320
324321void NativeDOM::releasePointerCapture (
325322 jsi::Runtime& rt,
326- jsi::Value nativeElementReference ,
323+ ShadowNode::Shared shadowNode ,
327324 double pointerId) {
328325 getPointerEventsProcessorFromRuntime (rt).releasePointerCapture (
329- static_cast <PointerIdentifier>(pointerId),
330- shadowNodeFromValue (rt, nativeElementReference).get ());
326+ static_cast <PointerIdentifier>(pointerId), shadowNode.get ());
331327}
332328
333329void NativeDOM::setPointerCapture (
334330 jsi::Runtime& rt,
335- jsi::Value nativeElementReference ,
331+ ShadowNode::Shared shadowNode ,
336332 double pointerId) {
337333 getPointerEventsProcessorFromRuntime (rt).setPointerCapture (
338- static_cast <PointerIdentifier>(pointerId),
339- shadowNodeFromValue (rt, nativeElementReference));
334+ static_cast <PointerIdentifier>(pointerId), shadowNode);
340335}
341336
342337#pragma mark - Methods from the `HTMLElement` interface (for `ReactNativeElement`).
@@ -345,8 +340,7 @@ std::tuple<
345340 /* offsetParent: */ jsi::Value,
346341 /* top: */ double ,
347342 /* left: */ double >
348- NativeDOM::getOffset (jsi::Runtime& rt, jsi::Value nativeElementReference) {
349- auto shadowNode = shadowNodeFromValue (rt, nativeElementReference);
343+ NativeDOM::getOffset (jsi::Runtime& rt, ShadowNode::Shared shadowNode) {
350344 auto currentRevision =
351345 getCurrentShadowTreeRevision (rt, shadowNode->getSurfaceId ());
352346 if (currentRevision == nullptr ) {
@@ -378,16 +372,15 @@ jsi::Value NativeDOM::linkRootNode(
378372 std::make_shared<InstanceHandle>(rt, instanceHandle, surfaceId);
379373 currentRevision->setInstanceHandle (instanceHandleWrapper);
380374
381- return valueFromShadowNode (rt, currentRevision);
375+ return Bridging<ShadowNode::Shared>:: toJs (rt, currentRevision);
382376}
383377
384378#pragma mark - Legacy layout APIs (for `ReactNativeElement`).
385379
386380void NativeDOM::measure (
387381 jsi::Runtime& rt,
388- jsi::Value nativeElementReference ,
382+ ShadowNode::Shared shadowNode ,
389383 jsi::Function callback) {
390- auto shadowNode = shadowNodeFromValue (rt, nativeElementReference);
391384 auto currentRevision =
392385 getCurrentShadowTreeRevision (rt, shadowNode->getSurfaceId ());
393386 if (currentRevision == nullptr ) {
@@ -409,9 +402,8 @@ void NativeDOM::measure(
409402
410403void NativeDOM::measureInWindow (
411404 jsi::Runtime& rt,
412- jsi::Value nativeElementReference ,
405+ ShadowNode::Shared shadowNode ,
413406 jsi::Function callback) {
414- auto shadowNode = shadowNodeFromValue (rt, nativeElementReference);
415407 auto currentRevision =
416408 getCurrentShadowTreeRevision (rt, shadowNode->getSurfaceId ());
417409 if (currentRevision == nullptr ) {
@@ -430,13 +422,10 @@ void NativeDOM::measureInWindow(
430422
431423void NativeDOM::measureLayout (
432424 jsi::Runtime& rt,
433- jsi::Value nativeElementReference ,
434- jsi::Value relativeToNativeElementReference ,
425+ ShadowNode::Shared shadowNode ,
426+ ShadowNode::Shared relativeToShadowNode ,
435427 jsi::Function onFail,
436428 jsi::Function onSuccess) {
437- auto shadowNode = shadowNodeFromValue (rt, nativeElementReference);
438- auto relativeToShadowNode =
439- shadowNodeFromValue (rt, relativeToNativeElementReference);
440429 auto currentRevision =
441430 getCurrentShadowTreeRevision (rt, shadowNode->getSurfaceId ());
442431 if (currentRevision == nullptr ) {
@@ -466,11 +455,10 @@ void NativeDOM::measureLayout(
466455
467456void NativeDOM::setNativeProps (
468457 jsi::Runtime& rt,
469- jsi::Value nativeElementReference ,
458+ ShadowNode::Shared shadowNode ,
470459 jsi::Value updatePayload) {
471460 getUIManagerFromRuntime (rt).setNativeProps_DEPRECATED (
472- shadowNodeFromValue (rt, nativeElementReference),
473- RawProps (rt, updatePayload));
461+ shadowNode, RawProps (rt, updatePayload));
474462}
475463
476464} // namespace facebook::react
0 commit comments