Update on resize (#94)

Fixes #88
This commit is contained in:
Christopher Chedeau 2020-01-03 18:35:14 -08:00 committed by GitHub
parent 8605af2b54
commit 66938ae5c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -645,6 +645,7 @@ const ELEMENT_TRANSLATE_AMOUNT = 1;
class App extends React.Component<{}, AppState> { class App extends React.Component<{}, AppState> {
public componentDidMount() { public componentDidMount() {
document.addEventListener("keydown", this.onKeyDown, false); document.addEventListener("keydown", this.onKeyDown, false);
window.addEventListener("resize", this.onResize, false);
const savedState = restore(); const savedState = restore();
if (savedState) { if (savedState) {
@ -654,6 +655,7 @@ class App extends React.Component<{}, AppState> {
public componentWillUnmount() { public componentWillUnmount() {
document.removeEventListener("keydown", this.onKeyDown, false); document.removeEventListener("keydown", this.onKeyDown, false);
window.removeEventListener("resize", this.onResize, false);
} }
public state: AppState = { public state: AppState = {
@ -669,6 +671,10 @@ class App extends React.Component<{}, AppState> {
scrollY: 0 scrollY: 0
}; };
private onResize = () => {
this.forceUpdate();
};
private onKeyDown = (event: KeyboardEvent) => { private onKeyDown = (event: KeyboardEvent) => {
if ((event.target as HTMLElement).nodeName === "INPUT") { if ((event.target as HTMLElement).nodeName === "INPUT") {
return; return;