Skip to content

Commit

Permalink
fix: add force update method into canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
paulobernardoaf committed Oct 7, 2023
1 parent d1c8c2a commit efcfbf7
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/components/canvas/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export class Canvas extends React.PureComponent<CanvasProps, CanvasState> {
this.ele.addEventListener('wheel', this.handleMouseWheel, {
passive: true
});
window.addEventListener('visibilitychange', () => this.forceCanvasUpdate());

window.document.addEventListener('copy', event => {
if (Object.keys(this.state.selected).length === 0) {
Expand Down Expand Up @@ -264,6 +265,20 @@ export class Canvas extends React.PureComponent<CanvasProps, CanvasState> {
this.props.onLoaded();
}

private forceCanvasUpdate() {
if (this.props.mouseState === MouseState.SELECT) {
this.props.onMouseStateChange(MouseState.DRAG);
setTimeout(() => {
this.props.onMouseStateChange(MouseState.SELECT);
});
} else if (this.props.mouseState === MouseState.DRAG) {
this.props.onMouseStateChange(MouseState.SELECT);
setTimeout(() => {
this.props.onMouseStateChange(MouseState.DRAG);
});
}
}

private loadPanZoom() {
const canvas = document.getElementById('panzoom');
const startingNode = this.getStartingNode();
Expand Down Expand Up @@ -311,8 +326,9 @@ export class Canvas extends React.PureComponent<CanvasProps, CanvasState> {
});

if (startingNode.position) {
const viewportWidth = document.documentElement.clientWidth;
this.panzoomInstance.moveTo(
TRANSFORM_START_X - startingNode.position.left,
viewportWidth / 2 - startingNode.position.left,
TRANSFORM_START_Y - startingNode.position.top
);
}
Expand Down

0 comments on commit efcfbf7

Please sign in to comment.