diff --git a/src/views/application.tsx b/src/views/application.tsx index 4e0d090..dfd3dca 100644 --- a/src/views/application.tsx +++ b/src/views/application.tsx @@ -186,11 +186,20 @@ export class GLCanvas extends Component { this.props.setGLCanvas(this.canvas) } + private container: HTMLElement | null = null + private containerRef = (container?: Element) => { + if (container instanceof HTMLElement) { + this.container = container + } else { + this.container = null + } + } + private maybeResize = () => { - if (!this.canvas) return + if (!this.container) return if (!this.props.canvasContext) return - let {width, height} = this.canvas.getBoundingClientRect() + let {width, height} = this.container.getBoundingClientRect() const widthInAppUnits = width const heightInAppUnits = height @@ -210,16 +219,13 @@ export class GLCanvas extends Component { if (this.props.canvasContext) { this.props.canvasContext.requestFrame() } - window.addEventListener('resize', this.onWindowResize) } componentWillReceiveProps(nextProps: GLCanvasProps) { if (this.props.canvasContext !== nextProps.canvasContext) { if (this.props.canvasContext) { - console.log('a') this.props.canvasContext.removeBeforeFrameHandler(this.maybeResize) } if (nextProps.canvasContext) { - console.log('b') nextProps.canvasContext.addBeforeFrameHandler(this.maybeResize) nextProps.canvasContext.requestFrame() } @@ -235,7 +241,11 @@ export class GLCanvas extends Component { window.removeEventListener('resize', this.onWindowResize) } render() { - return + return ( +
+ +
+ ) } }