Skip to content

Commit

Permalink
[DevTools] Highlight RN elements on hover (#25106)
Browse files Browse the repository at this point in the history
* [DevTools] Highlight RN elements on hover

* Remove unused TODO
  • Loading branch information
tyao1 authored and rickhanlonii committed Oct 5, 2022
1 parent 887c48c commit e05b3ad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ const SHOW_DURATION = 2000;
let timeoutID: TimeoutID | null = null;
let overlay: Overlay | null = null;

export function hideOverlay() {
export function hideOverlay(agent: Agent) {
if (window.document == null) {
agent.emit('hideNativeHighlight');
return;
}
timeoutID = null;

if (overlay !== null) {
Expand All @@ -31,8 +35,10 @@ export function showOverlay(
agent: Agent,
hideAfterTimeout: boolean,
) {
// TODO (npm-packages) Detect RN and support it somehow
if (window.document == null) {
if (elements != null && elements[0] != null) {
agent.emit('showNativeHighlight', elements[0]);
}
return;
}

Expand All @@ -51,6 +57,6 @@ export function showOverlay(
overlay.inspect(elements, componentName);

if (hideAfterTimeout) {
timeoutID = setTimeout(hideOverlay, SHOW_DURATION);
timeoutID = setTimeout(() => hideOverlay(agent), SHOW_DURATION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function setupHighlighter(
}

function stopInspectingNative() {
hideOverlay();
hideOverlay(agent);
removeListenersOnWindow(window);
iframesListeningTo.forEach(function(frame) {
try {
Expand Down Expand Up @@ -82,7 +82,7 @@ export default function setupHighlighter(
}

function clearNativeElementHighlight() {
hideOverlay();
hideOverlay(agent);
}

function highlightNativeElement({
Expand Down Expand Up @@ -129,7 +129,7 @@ export default function setupHighlighter(
bridge.send('syncSelectionToNativeElementsPanel');
}
} else {
hideOverlay();
hideOverlay(agent);
}
}

Expand Down

0 comments on commit e05b3ad

Please sign in to comment.