mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
494c47360f
Summary: Applies the autofix from the newly introduced `lint/sort-imports` ESLint rule. Changelog: [Internal] Reviewed By: cortinico, skinsshark Differential Revision: D39907798 fbshipit-source-id: 17f5f11b08a5b4bb66286816b78eb26e07e829b8
72 lines
1.8 KiB
JavaScript
72 lines
1.8 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @flow
|
|
*/
|
|
|
|
import type {
|
|
HostComponent,
|
|
TouchedViewDataAtPoint,
|
|
} from '../Renderer/shims/ReactNativeTypes';
|
|
|
|
const invariant = require('invariant');
|
|
const React = require('react');
|
|
|
|
export type HostRef = React.ElementRef<HostComponent<mixed>>;
|
|
export type ReactRenderer = {
|
|
rendererConfig: {
|
|
getInspectorDataForViewAtPoint: (
|
|
inspectedView: ?HostRef,
|
|
locationX: number,
|
|
locationY: number,
|
|
callback: Function,
|
|
) => void,
|
|
...
|
|
},
|
|
};
|
|
|
|
const hook = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
|
|
const renderers = findRenderers();
|
|
|
|
function findRenderers(): $ReadOnlyArray<ReactRenderer> {
|
|
const allRenderers = Array.from(hook.renderers.values());
|
|
invariant(
|
|
allRenderers.length >= 1,
|
|
'Expected to find at least one React Native renderer on DevTools hook.',
|
|
);
|
|
return allRenderers;
|
|
}
|
|
|
|
module.exports = function getInspectorDataForViewAtPoint(
|
|
inspectedView: ?HostRef,
|
|
locationX: number,
|
|
locationY: number,
|
|
callback: (viewData: TouchedViewDataAtPoint) => boolean,
|
|
) {
|
|
let shouldBreak = false;
|
|
// Check all renderers for inspector data.
|
|
for (let i = 0; i < renderers.length; i++) {
|
|
if (shouldBreak) {
|
|
break;
|
|
}
|
|
const renderer = renderers[i];
|
|
if (renderer?.rendererConfig?.getInspectorDataForViewAtPoint != null) {
|
|
renderer.rendererConfig.getInspectorDataForViewAtPoint(
|
|
inspectedView,
|
|
locationX,
|
|
locationY,
|
|
viewData => {
|
|
// Only return with non-empty view data since only one renderer will have this view.
|
|
if (viewData && viewData.hierarchy.length > 0) {
|
|
shouldBreak = callback(viewData);
|
|
}
|
|
},
|
|
);
|
|
}
|
|
}
|
|
};
|