Skip to content

Commit

Permalink
Allow Inspector to handle 2 renderers
Browse files Browse the repository at this point in the history
Summary: To avoid crashing when there are 2 different renderers, let the Inspector be a bit lenient.

Reviewed By: yungsters

Differential Revision: D7175338

fbshipit-source-id: ee5f86252f090361e42b6e2a93ae56c4c83c8c53
  • Loading branch information
fkgozali authored and facebook-github-bot committed Mar 7, 2018
1 parent d52569c commit d7b5b2e
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions Libraries/Inspector/Inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,26 @@ export type ReactRenderer = {
};

const hook = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
const renderer: ReactRenderer = findRenderer();
const renderers = findRenderers();

// required for devtools to be able to edit react native styles
hook.resolveRNStyle = require('flattenStyle');

function findRenderer(): ReactRenderer {
const renderers = hook._renderers;
const keys = Object.keys(renderers);
invariant(keys.length === 1, 'Expected to find exactly one React Native renderer on DevTools hook.');
return renderers[keys[0]];
function findRenderers(): $ReadOnlyArray<ReactRenderer> {
const allRenderers = Object.keys(hook._renderers).map(key => hook._renderers[key]);
invariant(allRenderers.length >= 1, 'Expected to find at least one React Native renderer on DevTools hook.');
return allRenderers;
}

function getInspectorDataForViewTag(touchedViewTag: number) {
for (let i = 0; i < renderers.length; i++) {
const renderer = renderers[i];
const inspectorData = renderer.getInspectorDataForViewTag(touchedViewTag);
if (inspectorData.hierarchy.length > 0) {
return inspectorData;
}
}
throw new Error('Expected to find at least one React renderer.');
}

class Inspector extends React.Component<{
Expand Down Expand Up @@ -170,7 +181,7 @@ class Inspector extends React.Component<{
props,
selection,
source,
} = renderer.getInspectorDataForViewTag(touchedViewTag);
} = getInspectorDataForViewTag(touchedViewTag);

if (this.state.devtoolsAgent) {
// Skip host leafs
Expand Down

0 comments on commit d7b5b2e

Please sign in to comment.