Skip to content

Commit

Permalink
refactor[renderer]: expose getInspectorDataForInstance in rendererConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxyq committed Jun 8, 2023
1 parent 9100456 commit fa3f8bd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 26 deletions.
1 change: 1 addition & 0 deletions packages/react-native-renderer/src/ReactFabric.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ injectIntoDevTools({
version: ReactVersion,
rendererPackageName: 'react-native-renderer',
rendererConfig: {
getInspectorDataForInstance,
getInspectorDataForViewTag: getInspectorDataForViewTag,
getInspectorDataForViewAtPoint: getInspectorDataForViewAtPoint.bind(
null,
Expand Down
31 changes: 5 additions & 26 deletions packages/react-native-renderer/src/ReactNativeFiberInspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,11 @@ function getInspectorDataForInstance(
selectedIndex,
source,
};
} else {
return (null: any);
}

throw new Error(
'getInspectorDataForInstance() is not available in production',
);
}

function getOwnerHierarchy(instance: any) {
Expand Down Expand Up @@ -157,30 +159,7 @@ function getInspectorDataForViewTag(viewTag: number): Object {
if (__DEV__) {
const closestInstance = getClosestInstanceFromNode(viewTag);

// Handle case where user clicks outside of ReactNative
if (!closestInstance) {
return {
hierarchy: [],
props: emptyObject,
selectedIndex: null,
source: null,
};
}

const fiber = findCurrentFiberUsingSlowPath(closestInstance);
const fiberHierarchy = getOwnerHierarchy(fiber);
const instance = lastNonHostInstance(fiberHierarchy);
const hierarchy = createHierarchy(fiberHierarchy);
const props = getHostProps(instance);
const source = instance._debugSource;
const selectedIndex = fiberHierarchy.indexOf(instance);

return {
hierarchy,
props,
selectedIndex,
source,
};
return getInspectorDataForInstance(closestInstance);
} else {
throw new Error(
'getInspectorDataForViewTag() is not available in production',
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-renderer/src/ReactNativeRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ injectIntoDevTools({
version: ReactVersion,
rendererPackageName: 'react-native-renderer',
rendererConfig: {
getInspectorDataForInstance,
getInspectorDataForViewTag: getInspectorDataForViewTag,
getInspectorDataForViewAtPoint: getInspectorDataForViewAtPoint.bind(
null,
Expand Down

0 comments on commit fa3f8bd

Please sign in to comment.