@@ -44,6 +44,7 @@ import {
44
44
zeroPoint ,
45
45
} from './view-base' ;
46
46
import {
47
+ ComponentMeasuresView ,
47
48
FlamechartView ,
48
49
NativeEventsView ,
49
50
ReactMeasuresView ,
@@ -132,6 +133,7 @@ function AutoSizedCanvas({data, height, width}: AutoSizedCanvasProps) {
132
133
const nativeEventsViewRef = useRef ( null ) ;
133
134
const schedulingEventsViewRef = useRef ( null ) ;
134
135
const suspenseEventsViewRef = useRef ( null ) ;
136
+ const componentMeasuresViewRef = useRef ( null ) ;
135
137
const reactMeasuresViewRef = useRef ( null ) ;
136
138
const flamechartViewRef = useRef ( null ) ;
137
139
const syncedHorizontalPanAndZoomViewsRef = useRef < HorizontalPanAndZoomView [ ] > (
@@ -259,6 +261,17 @@ function AutoSizedCanvas({data, height, width}: AutoSizedCanvasProps) {
259
261
true ,
260
262
) ;
261
263
264
+ let componentMeasuresViewWrapper = null ;
265
+ if ( data . componentMeasures . length > 0 ) {
266
+ const componentMeasuresView = new ComponentMeasuresView (
267
+ surface ,
268
+ defaultFrame ,
269
+ data ,
270
+ ) ;
271
+ componentMeasuresViewRef . current = componentMeasuresView ;
272
+ componentMeasuresViewWrapper = createViewHelper ( componentMeasuresView ) ;
273
+ }
274
+
262
275
const flamechartView = new FlamechartView (
263
276
surface ,
264
277
defaultFrame ,
@@ -293,6 +306,9 @@ function AutoSizedCanvas({data, height, width}: AutoSizedCanvasProps) {
293
306
rootView . addSubview ( suspenseEventsViewWrapper ) ;
294
307
}
295
308
rootView . addSubview ( reactMeasuresViewWrapper ) ;
309
+ if ( componentMeasuresViewWrapper !== null ) {
310
+ rootView . addSubview ( componentMeasuresViewWrapper ) ;
311
+ }
296
312
rootView . addSubview ( flamechartViewWrapper ) ;
297
313
298
314
// If subviews are less than the available height, fill remaining height with a solid color.
@@ -323,6 +339,7 @@ function AutoSizedCanvas({data, height, width}: AutoSizedCanvasProps) {
323
339
if ( prevHoverEvent === null ) {
324
340
return prevHoverEvent ;
325
341
} else if (
342
+ prevHoverEvent . componentMeasure !== null ||
326
343
prevHoverEvent . flamechartStackFrame !== null ||
327
344
prevHoverEvent . measure !== null ||
328
345
prevHoverEvent . nativeEvent !== null ||
@@ -331,6 +348,7 @@ function AutoSizedCanvas({data, height, width}: AutoSizedCanvasProps) {
331
348
prevHoverEvent . userTimingMark !== null
332
349
) {
333
350
return {
351
+ componentMeasure : null ,
334
352
data : prevHoverEvent . data ,
335
353
flamechartStackFrame : null ,
336
354
measure : null ,
@@ -378,6 +396,7 @@ function AutoSizedCanvas({data, height, width}: AutoSizedCanvasProps) {
378
396
userTimingMarksView . onHover = userTimingMark => {
379
397
if ( ! hoveredEvent || hoveredEvent . userTimingMark !== userTimingMark ) {
380
398
setHoveredEvent ( {
399
+ componentMeasure : null ,
381
400
data,
382
401
flamechartStackFrame : null ,
383
402
measure : null ,
@@ -395,6 +414,7 @@ function AutoSizedCanvas({data, height, width}: AutoSizedCanvasProps) {
395
414
nativeEventsView . onHover = nativeEvent => {
396
415
if ( ! hoveredEvent || hoveredEvent . nativeEvent !== nativeEvent ) {
397
416
setHoveredEvent ( {
417
+ componentMeasure : null ,
398
418
data,
399
419
flamechartStackFrame : null ,
400
420
measure : null ,
@@ -412,6 +432,7 @@ function AutoSizedCanvas({data, height, width}: AutoSizedCanvasProps) {
412
432
schedulingEventsView . onHover = schedulingEvent => {
413
433
if ( ! hoveredEvent || hoveredEvent . schedulingEvent !== schedulingEvent ) {
414
434
setHoveredEvent ( {
435
+ componentMeasure : null ,
415
436
data,
416
437
flamechartStackFrame : null ,
417
438
measure : null ,
@@ -429,6 +450,7 @@ function AutoSizedCanvas({data, height, width}: AutoSizedCanvasProps) {
429
450
suspenseEventsView . onHover = suspenseEvent => {
430
451
if ( ! hoveredEvent || hoveredEvent . suspenseEvent !== suspenseEvent ) {
431
452
setHoveredEvent ( {
453
+ componentMeasure : null ,
432
454
data,
433
455
flamechartStackFrame : null ,
434
456
measure : null ,
@@ -446,6 +468,7 @@ function AutoSizedCanvas({data, height, width}: AutoSizedCanvasProps) {
446
468
reactMeasuresView . onHover = measure => {
447
469
if ( ! hoveredEvent || hoveredEvent . measure !== measure ) {
448
470
setHoveredEvent ( {
471
+ componentMeasure : null ,
449
472
data,
450
473
flamechartStackFrame : null ,
451
474
measure,
@@ -458,6 +481,27 @@ function AutoSizedCanvas({data, height, width}: AutoSizedCanvasProps) {
458
481
} ;
459
482
}
460
483
484
+ const { current : componentMeasuresView } = componentMeasuresViewRef ;
485
+ if ( componentMeasuresView ) {
486
+ componentMeasuresView . onHover = componentMeasure => {
487
+ if (
488
+ ! hoveredEvent ||
489
+ hoveredEvent . componentMeasure !== componentMeasure
490
+ ) {
491
+ setHoveredEvent ( {
492
+ componentMeasure,
493
+ data,
494
+ flamechartStackFrame : null ,
495
+ measure : null ,
496
+ nativeEvent : null ,
497
+ schedulingEvent : null ,
498
+ suspenseEvent : null ,
499
+ userTimingMark : null ,
500
+ } ) ;
501
+ }
502
+ } ;
503
+ }
504
+
461
505
const { current : flamechartView } = flamechartViewRef ;
462
506
if ( flamechartView ) {
463
507
flamechartView . setOnHover ( flamechartStackFrame => {
@@ -466,6 +510,7 @@ function AutoSizedCanvas({data, height, width}: AutoSizedCanvasProps) {
466
510
hoveredEvent . flamechartStackFrame !== flamechartStackFrame
467
511
) {
468
512
setHoveredEvent ( {
513
+ componentMeasure : null ,
469
514
data,
470
515
flamechartStackFrame,
471
516
measure : null ,
@@ -540,13 +585,21 @@ function AutoSizedCanvas({data, height, width}: AutoSizedCanvasProps) {
540
585
return null ;
541
586
}
542
587
const {
588
+ componentMeasure,
543
589
flamechartStackFrame,
544
590
measure,
545
591
schedulingEvent,
546
592
suspenseEvent,
547
593
} = contextData . hoveredEvent ;
548
594
return (
549
595
< Fragment >
596
+ { componentMeasure !== null && (
597
+ < ContextMenuItem
598
+ onClick = { ( ) => copy ( componentMeasure . componentName ) }
599
+ title = "Copy component name" >
600
+ Copy component name
601
+ </ ContextMenuItem >
602
+ ) }
550
603
{ schedulingEvent !== null && (
551
604
< ContextMenuItem
552
605
onClick = { ( ) => copy ( schedulingEvent . componentName ) }
0 commit comments