Fix viewer not resizing on window resize
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Siklos 2022-08-05 20:04:15 +02:00
parent a059a3d710
commit e120072cd9

View file

@ -11,8 +11,37 @@ interface ISVGProps {
selected: ContainerModel | null
}
interface ISVGState {
viewerWidth: number,
viewerHeight: number,
}
export class SVG extends React.PureComponent<ISVGProps> {
public static ID = 'svg';
public state: ISVGState;
constructor(props: ISVGProps) {
super(props);
this.state = {
viewerWidth: window.innerWidth,
viewerHeight: window.innerHeight
};
}
resizeViewBox(): void {
this.setState({
viewerWidth: window.innerWidth,
viewerHeight: window.innerHeight
});
}
componentDidMount(): void {
window.addEventListener('resize', this.resizeViewBox.bind(this));
}
componentWillUnmount(): void {
window.removeEventListener('resize', this.resizeViewBox.bind(this));
}
render(): JSX.Element {
const xmlns = '<http://www.w3.org/2000/svg>';
@ -33,8 +62,8 @@ export class SVG extends React.PureComponent<ISVGProps> {
return (
<div id={SVG.ID}>
<UncontrolledReactSVGPanZoom
width={window.innerWidth}
height={window.innerHeight}
width={this.state.viewerWidth}
height={this.state.viewerHeight}
background={'#ffffff'}
defaultTool='pan'
miniatureProps={{