@@ -12,6 +12,8 @@ import type {Rect} from '../utils';
1212import type { NativeType } from '../../types' ;
1313import type Agent from '../../agent' ;
1414
15+ import { isReactNativeEnvironment } from 'react-devtools-shared/src/frontend/utils' ;
16+
1517const OUTLINE_COLOR = '#f0f0f0' ;
1618
1719// Note these colors are in sync with DevTools Profiler chart colors.
@@ -30,17 +32,16 @@ const COLORS = [
3032
3133let canvas : HTMLCanvasElement | null = null ;
3234
33- export function draw ( nodeToData : Map < NativeType , Data > , agent : Agent) : void {
34- if ( window . document == null ) {
35- const nodesToDraw = [ ] ;
36- iterateNodes ( nodeToData , ( _ , color , node ) => {
37- nodesToDraw . push ( { node, color} ) ;
38- } ) ;
39-
40- agent . emit ( 'drawTraceUpdates' , nodesToDraw ) ;
41- return ;
42- }
35+ function drawNative ( nodeToData : Map < NativeType , Data > , agent : Agent ) {
36+ const nodesToDraw = [ ] ;
37+ iterateNodes ( nodeToData , ( _ , color , node ) => {
38+ nodesToDraw . push ( { node, color} ) ;
39+ } ) ;
4340
41+ agent . emit ( 'drawTraceUpdates' , nodesToDraw ) ;
42+ }
43+
44+ function drawWeb ( nodeToData : Map < NativeType , Data > ) {
4445 if ( canvas === null ) {
4546 initialize ( ) ;
4647 }
@@ -58,6 +59,12 @@ export function draw(nodeToData: Map<NativeType, Data>, agent: Agent): void {
5859 } ) ;
5960}
6061
62+ export function draw ( nodeToData : Map < NativeType , Data > , agent : Agent) : void {
63+ return isReactNativeEnvironment ( )
64+ ? drawNative ( nodeToData , agent )
65+ : drawWeb ( nodeToData ) ;
66+ }
67+
6168function iterateNodes (
6269 nodeToData : Map < NativeType , Data > ,
6370 execute : ( rect : Rect | null , color : string , node : NativeType ) = > void ,
@@ -97,12 +104,11 @@ function drawBorder(
97104 context . setLineDash ( [ 0 ] ) ;
98105}
99106
100- export function destroy ( agent : Agent ) : void {
101- if ( window . document == null ) {
102- agent . emit ( 'disableTraceUpdates' ) ;
103- return ;
104- }
107+ function destroyNative ( agent : Agent ) {
108+ agent . emit ( 'disableTraceUpdates' ) ;
109+ }
105110
111+ function destroyWeb ( ) {
106112 if ( canvas !== null ) {
107113 if ( canvas . parentNode != null ) {
108114 canvas . parentNode . removeChild ( canvas ) ;
@@ -111,6 +117,10 @@ export function destroy(agent: Agent): void {
111117 }
112118}
113119
120+ export function destroy ( agent : Agent ) : void {
121+ return isReactNativeEnvironment ( ) ? destroyNative ( agent ) : destroyWeb ( ) ;
122+ }
123+
114124function initialize ( ) : void {
115125 canvas = window . document . createElement ( 'canvas' ) ;
116126 canvas . style . cssText = `
0 commit comments