From cd395b552b70709f40fc00d7ae85fdeec0416763 Mon Sep 17 00:00:00 2001 From: Ruslan Lesiutin Date: Mon, 4 Dec 2023 13:06:16 -0800 Subject: [PATCH] feat[ReactFabricPrivateInterface]: add getInternalInstanceHandleFromPublicInstance (#41786) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/41786 Changelog: [Internal] This is the preprequisite for https://github.com/facebook/react/pull/27783 Reviewed By: rubennorte Differential Revision: D51808831 fbshipit-source-id: c8ddf67d7ad35a670fa462c246dcb7230ba47716 --- .../ReactFabricPublicInstance.js | 11 +++++++++++ .../ReactPrivate/ReactNativePrivateInterface.js | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/packages/react-native/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance.js b/packages/react-native/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance.js index 71730351f2a321..2502bab8692302 100644 --- a/packages/react-native/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance.js +++ b/packages/react-native/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance.js @@ -8,6 +8,11 @@ * @flow strict-local */ +/** + * This module is meant to be used by the React renderers to create public + * instances and get some data from them (like their instance handle / fiber). + */ + import type ReactNativeElement from '../../DOM/Nodes/ReactNativeElement'; import type ReadOnlyText from '../../DOM/Nodes/ReadOnlyText'; import typeof ReactFabricType from '../../Renderer/shims/ReactFabric'; @@ -79,3 +84,9 @@ export function getNodeFromPublicInstance( publicInstance.__internalInstanceHandle, ); } + +export function getInternalInstanceHandleFromPublicInstance( + publicInstance: ReactFabricHostComponent | ReactNativeElement, +): InternalInstanceHandle { + return publicInstance.__internalInstanceHandle; +} diff --git a/packages/react-native/Libraries/ReactPrivate/ReactNativePrivateInterface.js b/packages/react-native/Libraries/ReactPrivate/ReactNativePrivateInterface.js index 7e50aee2c9fa4b..206b826f14ed0d 100644 --- a/packages/react-native/Libraries/ReactPrivate/ReactNativePrivateInterface.js +++ b/packages/react-native/Libraries/ReactPrivate/ReactNativePrivateInterface.js @@ -19,6 +19,7 @@ import typeof CustomEvent from '../Events/CustomEvent'; import typeof { createPublicInstance, createPublicTextInstance, + getInternalInstanceHandleFromPublicInstance, getNativeTagFromPublicInstance, getNodeFromPublicInstance, } from '../ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance'; @@ -108,4 +109,8 @@ module.exports = { return require('../ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance') .getNodeFromPublicInstance; }, + get getInternalInstanceHandleFromPublicInstance(): getInternalInstanceHandleFromPublicInstance { + return require('../ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance') + .getInternalInstanceHandleFromPublicInstance; + }, };