Skip to content

Commit

Permalink
Fix (Canvas): Issue of sometimes the canvas don't draw the image caus…
Browse files Browse the repository at this point in the history
…e of the canvas dimensions are not set (Issue #251)
  • Loading branch information
AhmeeedMostafa committed Feb 9, 2023
1 parent 4d5256a commit 0fbbf82
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** External Dependencies */
import React, { useCallback } from 'react';
import React, { useCallback, useEffect, useRef } from 'react';

/** Internal Dependencies */
import { DesignLayer, TransformersLayer } from 'components/Layers';
Expand All @@ -13,6 +13,7 @@ import { CanvasContainer, StyledOrignalImage } from './MainCanvas.styled';
const MainCanvas = () => {
const [observeResize] = useResizeObserver();
const providedAppContext = useStore();
const canvasContainerRef = useRef(null);

const setNewCanvasSize = useCallback(
({ width: containerWidth, height: containerHeight }) => {
Expand All @@ -27,15 +28,12 @@ const MainCanvas = () => {
[],
);

const observeCanvasContainerResizing = useCallback((element) => {
observeResize(element, setNewCanvasSize);
useEffect(() => {
observeResize(canvasContainerRef.current, setNewCanvasSize);
}, []);

return (
<CanvasContainer
className="FIE_canvas-container"
ref={observeCanvasContainerResizing}
>
<CanvasContainer className="FIE_canvas-container" ref={canvasContainerRef}>
{!providedAppContext.textIdOfEditableContent && <NodeControls />}
{providedAppContext.isShowOriginalImage && (
<StyledOrignalImage
Expand Down

0 comments on commit 0fbbf82

Please sign in to comment.