Skip to content

Commit 1815253

Browse files
authored
[DevTools] Highlight RN elements on hover (#25106)
* [DevTools] Highlight RN elements on hover * Remove unused TODO
1 parent 3d443ca commit 1815253

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

packages/react-devtools-shared/src/backend/views/Highlighter/Highlighter.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ const SHOW_DURATION = 2000;
1616
let timeoutID: TimeoutID | null = null;
1717
let overlay: Overlay | null = null;
1818

19-
export function hideOverlay() {
19+
export function hideOverlay(agent: Agent) {
20+
if (window.document == null) {
21+
agent.emit('hideNativeHighlight');
22+
return;
23+
}
2024
timeoutID = null;
2125

2226
if (overlay !== null) {
@@ -31,8 +35,10 @@ export function showOverlay(
3135
agent: Agent,
3236
hideAfterTimeout: boolean,
3337
) {
34-
// TODO (npm-packages) Detect RN and support it somehow
3538
if (window.document == null) {
39+
if (elements != null && elements[0] != null) {
40+
agent.emit('showNativeHighlight', elements[0]);
41+
}
3642
return;
3743
}
3844

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

5359
if (hideAfterTimeout) {
54-
timeoutID = setTimeout(hideOverlay, SHOW_DURATION);
60+
timeoutID = setTimeout(() => hideOverlay(agent), SHOW_DURATION);
5561
}
5662
}

packages/react-devtools-shared/src/backend/views/Highlighter/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default function setupHighlighter(
5454
}
5555

5656
function stopInspectingNative() {
57-
hideOverlay();
57+
hideOverlay(agent);
5858
removeListenersOnWindow(window);
5959
iframesListeningTo.forEach(function(frame) {
6060
try {
@@ -82,7 +82,7 @@ export default function setupHighlighter(
8282
}
8383

8484
function clearNativeElementHighlight() {
85-
hideOverlay();
85+
hideOverlay(agent);
8686
}
8787

8888
function highlightNativeElement({
@@ -129,7 +129,7 @@ export default function setupHighlighter(
129129
bridge.send('syncSelectionToNativeElementsPanel');
130130
}
131131
} else {
132-
hideOverlay();
132+
hideOverlay(agent);
133133
}
134134
}
135135

0 commit comments

Comments
 (0)