10
10
import type { Snapshot , ReactProfilerData } from '../types' ;
11
11
import type {
12
12
Interaction ,
13
- MouseMoveInteraction ,
13
+ Point ,
14
14
Rect ,
15
15
Size ,
16
16
Surface ,
@@ -67,6 +67,10 @@ export class SnapshotsView extends View {
67
67
// draw them at fixed intervals and just show the nearest one.
68
68
while ( x < visibleArea . origin . x + visibleArea . size . width ) {
69
69
const snapshot = this . _findClosestSnapshot ( x ) ;
70
+ if ( snapshot === null ) {
71
+ // This shold never happen.
72
+ break ;
73
+ }
70
74
71
75
const scaledHeight = SNAPSHOT_HEIGHT ;
72
76
const scaledWidth = ( snapshot . width * SNAPSHOT_HEIGHT ) / snapshot . height ;
@@ -97,7 +101,11 @@ export class SnapshotsView extends View {
97
101
handleInteraction ( interaction : Interaction , viewRefs : ViewRefs ) {
98
102
switch ( interaction . type ) {
99
103
case 'mousemove' :
100
- this . _handleMouseMove ( interaction , viewRefs ) ;
104
+ case 'wheel-control' :
105
+ case 'wheel-meta' :
106
+ case 'wheel-plain' :
107
+ case 'wheel-shift' :
108
+ this . _updateHover ( interaction . payload . location , viewRefs ) ;
101
109
break ;
102
110
}
103
111
}
@@ -125,6 +133,14 @@ export class SnapshotsView extends View {
125
133
context . clip ( ) ;
126
134
}
127
135
136
+ context . fillStyle = COLORS . REACT_RESIZE_BAR_BORDER ;
137
+ context . fillRect (
138
+ imageRect . origin . x ,
139
+ imageRect . origin . y ,
140
+ imageRect . size . width ,
141
+ imageRect . size . height ,
142
+ ) ;
143
+
128
144
// $FlowFixMe Flow doesn't know about the 9 argument variant of drawImage()
129
145
context . drawImage (
130
146
snapshot . image ,
@@ -138,20 +154,20 @@ export class SnapshotsView extends View {
138
154
snapshot . height ,
139
155
140
156
// Canvas coordinates
141
- imageRect . origin . x ,
142
- imageRect . origin . y ,
157
+ imageRect . origin . x + BORDER_SIZE ,
158
+ imageRect . origin . y + BORDER_SIZE ,
143
159
144
160
// Scaled image size
145
- imageRect . size . width ,
146
- imageRect . size . height ,
161
+ imageRect . size . width - BORDER_SIZE * 2 ,
162
+ imageRect . size . height - BORDER_SIZE * 2 ,
147
163
) ;
148
164
149
165
if ( shouldClip ) {
150
166
context . restore ( ) ;
151
167
}
152
168
}
153
169
154
- _findClosestSnapshot ( x : number ) : Snapshot {
170
+ _findClosestSnapshot ( x : number ) : Snapshot | null {
155
171
const frame = this . frame ;
156
172
const scaleFactor = positioningScaleFactor (
157
173
this . _intrinsicSize . width ,
@@ -178,26 +194,25 @@ export class SnapshotsView extends View {
178
194
}
179
195
}
180
196
181
- return snapshots [ stopIndex ] ;
197
+ return snapshots [ stopIndex ] || null ;
182
198
}
183
199
184
200
/**
185
201
* @private
186
202
*/
187
- _handleMouseMove ( interaction : MouseMoveInteraction , viewRefs : ViewRefs ) {
203
+ _updateHover ( location : Point , viewRefs : ViewRefs ) {
188
204
const { onHover, visibleArea} = this ;
189
205
if ( ! onHover ) {
190
206
return ;
191
207
}
192
208
193
- const { location} = interaction . payload ;
194
209
if ( ! rectContainsPoint ( location , visibleArea ) ) {
195
210
onHover ( null ) ;
196
211
return ;
197
212
}
198
213
199
214
const snapshot = this . _findClosestSnapshot ( location . x ) ;
200
- if ( snapshot ) {
215
+ if ( snapshot !== null ) {
201
216
this . currentCursor = 'context-menu' ;
202
217
viewRefs . hoveredView = this ;
203
218
onHover ( snapshot ) ;
0 commit comments