Fix NPE in Interactive.tsx

Summary: Fixed some incorrect non-null assertions that showed up in monitoring.

Reviewed By: timur-valiev

Differential Revision: D32278433

fbshipit-source-id: afe4913d8aef38c371461b4d0b817b2625153de1
This commit is contained in:
Michel Weststrate
2021-11-09 05:20:57 -08:00
committed by Facebook GitHub Bot
parent 6385111028
commit 96cd25fcc1

View File

@@ -406,9 +406,12 @@ export class Interactive extends React.Component<
calculateResize(event: MouseEvent) { calculateResize(event: MouseEvent) {
const {resizingInitialCursor, resizingInitialRect, resizingSides} = const {resizingInitialCursor, resizingInitialRect, resizingSides} =
this.state; this.state;
if (!resizingSides || !resizingInitialCursor) {
return;
}
const deltaLeft = resizingInitialCursor!.left - event.clientX; const deltaLeft = resizingInitialCursor.left - event.clientX;
const deltaTop = resizingInitialCursor!.top - event.clientY; const deltaTop = resizingInitialCursor.top - event.clientY;
let newLeft = resizingInitialRect!.left; let newLeft = resizingInitialRect!.left;
let newTop = resizingInitialRect!.top; let newTop = resizingInitialRect!.top;
@@ -417,19 +420,19 @@ export class Interactive extends React.Component<
let newHeight = resizingInitialRect!.height; let newHeight = resizingInitialRect!.height;
// right // right
if (resizingSides!.right === true) { if (resizingSides.right === true) {
newWidth -= deltaLeft; newWidth -= deltaLeft;
} }
// bottom // bottom
if (resizingSides!.bottom === true) { if (resizingSides.bottom === true) {
newHeight -= deltaTop; newHeight -= deltaTop;
} }
const rect = this.getRect(); const rect = this.getRect();
// left // left
if (resizingSides!.left === true) { if (resizingSides.left === true) {
newLeft -= deltaLeft; newLeft -= deltaLeft;
newWidth += deltaLeft; newWidth += deltaLeft;
@@ -446,7 +449,7 @@ export class Interactive extends React.Component<
} }
// top // top
if (resizingSides!.top === true) { if (resizingSides.top === true) {
newTop -= deltaTop; newTop -= deltaTop;
newHeight += deltaTop; newHeight += deltaTop;
@@ -465,23 +468,23 @@ export class Interactive extends React.Component<
if (event.altKey) { if (event.altKey) {
const windows = this.getPossibleTargetWindows(rect); const windows = this.getPossibleTargetWindows(rect);
if (resizingSides!.left === true) { if (resizingSides.left === true) {
const newLeft2 = maybeSnapLeft(rect, windows, newLeft); const newLeft2 = maybeSnapLeft(rect, windows, newLeft);
newWidth += newLeft - newLeft2; newWidth += newLeft - newLeft2;
newLeft = newLeft2; newLeft = newLeft2;
} }
if (resizingSides!.top === true) { if (resizingSides.top === true) {
const newTop2 = maybeSnapTop(rect, windows, newTop); const newTop2 = maybeSnapTop(rect, windows, newTop);
newHeight += newTop - newTop2; newHeight += newTop - newTop2;
newTop = newTop2; newTop = newTop2;
} }
if (resizingSides!.bottom === true) { if (resizingSides.bottom === true) {
newHeight = maybeSnapTop(rect, windows, newTop + newHeight) - newTop; newHeight = maybeSnapTop(rect, windows, newTop + newHeight) - newTop;
} }
if (resizingSides!.right === true) { if (resizingSides.right === true) {
newWidth = maybeSnapLeft(rect, windows, newLeft + newWidth) - newLeft; newWidth = maybeSnapLeft(rect, windows, newLeft + newWidth) - newLeft;
} }
} }