diff --git a/src/linecomps.tsx b/src/linecomps.tsx index 53248b19..7621dd50 100644 --- a/src/linecomps.tsx +++ b/src/linecomps.tsx @@ -531,7 +531,7 @@ class LineCmd extends React.Component<{screen : LineContainerModel, line : LineT - +
diff --git a/src/simplerenderer.tsx b/src/simplerenderer.tsx index ca120d70..fd65936f 100644 --- a/src/simplerenderer.tsx +++ b/src/simplerenderer.tsx @@ -52,6 +52,7 @@ class SimpleBlobRendererModel { if (this.savedHeight != newHeight) { this.savedHeight = newHeight; this.api.saveHeight(newHeight); + console.log("saveheight", sprintf("[%d]", this.context.lineNum), newHeight); } } @@ -118,9 +119,10 @@ function apiAdapter(lcm : LineContainerModel, line : LineType, cmd : Cmd) : Rend } @mobxReact.observer -class SimpleBlobRenderer extends React.Component<{lcm : LineContainerModel, line : LineType, cmd : Cmd, plugin : RendererPluginType}, {}> { +class SimpleBlobRenderer extends React.Component<{lcm : LineContainerModel, line : LineType, cmd : Cmd, plugin : RendererPluginType, onHeightChange : () => void}, {}> { model : SimpleBlobRendererModel; wrapperDivRef : React.RefObject = React.createRef(); + rszObs : ResizeObserver; constructor(props : any) { super(props); @@ -151,27 +153,44 @@ class SimpleBlobRenderer extends React.Component<{lcm : LineContainerModel, line this.model.initialize(initOpts); lcm.registerRenderer(line.cmdid, this.model); } + + handleResize(entries : ResizeObserverEntry[]) : void { + console.log("simplerender resize", sprintf("[%d]", this.model.context.lineNum), entries); + if (this.props.onHeightChange) { + this.props.onHeightChange(); + } + if (!this.model.loading.get() && this.wrapperDivRef.current != null) { + let height = this.wrapperDivRef.current.offsetHeight; + this.model.updateHeight(height); + } + } + + checkRszObs() { + if (this.rszObs != null) { + return; + } + if (this.wrapperDivRef.current == null) { + return; + } + this.rszObs = new ResizeObserver(this.handleResize.bind(this)); + this.rszObs.observe(this.wrapperDivRef.current); + } componentDidMount() { - this.checkHeight(); + this.checkRszObs(); } componentWillUnmount() { let {lcm, line} = this.props; lcm.unloadRenderer(line.cmdid); + if (this.rszObs != null) { + this.rszObs.disconnect(); + this.rszObs = null; + } } componentDidUpdate() { - this.checkHeight(); - } - - checkHeight() : void { - // TODO: use resizeobserver instead of ref. - if (this.wrapperDivRef.current == null) { - return; - } - let height = this.wrapperDivRef.current.offsetHeight; - this.model.updateHeight(height); + this.checkRszObs(); } render() { @@ -179,7 +198,7 @@ class SimpleBlobRenderer extends React.Component<{lcm : LineContainerModel, line let model = this.model; if (model.loading.get()) { let height = this.model.savedHeight; - return (
...
); + return (
...
); } let Comp = plugin.component; let dataBlob = new Blob([model.ptyData.data]); diff --git a/src/types.ts b/src/types.ts index e679c019..99c3cf2d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -405,17 +405,6 @@ type SimpleBlobRendererComponent = React.ComponentType<{data : Blob, context : R type SimpleJsonRendererComponent = React.ComponentType<{data : any, context : RendererContext, opts : RendererOpts}>; type FullRendererComponent = React.ComponentType<{model : any}>; -type OldRendererModel = { - dispose : () => void, - reload : (delayMs : number) => void, - receiveData : (pos : number, data : Uint8Array, reason? : string) => void, - cmdDone : () => void, - resizeWindow : (size : WindowSize) => void, - resizeCols : (cols : number) => void, - giveFocus : () => void, - getUsedRows : () => number, -}; - type WindowSize = { height : number, width: number,