mirror of
https://github.com/wassname/talk.git
synced 2026-08-09 12:30:42 +08:00
37 lines
832 B
TypeScript
37 lines
832 B
TypeScript
import { Component } from "react";
|
|
|
|
/**
|
|
* A container that adapts the window height to the current body size
|
|
* when this is mounted or updated.
|
|
*/
|
|
export default class AutoHeightContainer extends Component {
|
|
private timeout: any = null;
|
|
|
|
private updateWindowSizeCallback = () => {
|
|
clearTimeout(this.timeout);
|
|
this.timeout = setTimeout(() => {
|
|
const innerHeight = window.document.body.offsetHeight;
|
|
window.resizeTo(
|
|
window.outerWidth,
|
|
innerHeight + window.outerHeight - window.innerHeight
|
|
);
|
|
}, 0);
|
|
};
|
|
|
|
private updateWindowSize() {
|
|
window.requestAnimationFrame(this.updateWindowSizeCallback);
|
|
}
|
|
|
|
public componentDidMount() {
|
|
this.updateWindowSize();
|
|
}
|
|
|
|
public componentDidUpdate() {
|
|
this.updateWindowSize();
|
|
}
|
|
|
|
public render() {
|
|
return null;
|
|
}
|
|
}
|