Skip to content

Commit c5b4b2b

Browse files
committed
Provide function to access public instance from internal instance handle in Fabric
1 parent 842bd78 commit c5b4b2b

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

packages/react-native-renderer/src/ReactFabric.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
sendAccessibilityEvent,
4141
getNodeFromInternalInstanceHandle,
4242
} from './ReactNativePublicCompat';
43+
import {getPublicInstanceFromInternalInstanceHandle} from './ReactFabricHostConfig';
4344

4445
// $FlowFixMe[missing-local-annot]
4546
function onRecoverableError(error) {
@@ -124,6 +125,10 @@ export {
124125
// This method allows it to acess the most recent shadow node for
125126
// the instance (it's only accessible through it).
126127
getNodeFromInternalInstanceHandle,
128+
// Fabric native methods to traverse the host tree return the same internal
129+
// instance handles we use to dispatch events. This provides a way to access
130+
// the public instances we created from them (potentially created lazily).
131+
getPublicInstanceFromInternalInstanceHandle,
127132
};
128133

129134
injectIntoDevTools({

packages/react-native-renderer/src/ReactFabricHostConfig.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,13 @@ export function getPublicInstance(instance: Instance): null | PublicInstance {
241241
return null;
242242
}
243243

244+
export function getPublicInstanceFromInternalInstanceHandle(
245+
internalInstanceHandle: Object,
246+
): null | PublicInstance {
247+
const instance: Instance = internalInstanceHandle.stateNode;
248+
return getPublicInstance(instance);
249+
}
250+
244251
export function prepareForCommit(containerInfo: Container): null | Object {
245252
// Noop
246253
return null;

packages/react-native-renderer/src/ReactNativeTypes.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ export type ReactNativeType = {
213213
};
214214

215215
export opaque type Node = mixed;
216+
type InternalInstanceHandle = mixed;
217+
type PublicInstance = mixed;
216218

217219
export type ReactFabricType = {
218220
findHostInstance_DEPRECATED<TElementType: ElementType>(
@@ -237,7 +239,12 @@ export type ReactFabricType = {
237239
concurrentRoot: ?boolean,
238240
): ?ElementRef<ElementType>,
239241
unmountComponentAtNode(containerTag: number): void,
240-
getNodeFromInternalInstanceHandle(internalInstanceHandle: mixed): ?Node,
242+
getNodeFromInternalInstanceHandle(
243+
internalInstanceHandle: InternalInstanceHandle,
244+
): ?Node,
245+
getPublicInstanceFromInternalInstanceHandle(
246+
internalInstanceHandle: InternalInstanceHandle,
247+
): PublicInstance,
241248
...
242249
};
243250

0 commit comments

Comments
 (0)