Skip to content

Commit

Permalink
Block Editor: Animate useScaleCanvas() only when toggling zoomed out …
Browse files Browse the repository at this point in the history
…mode (#67481)

Co-authored-by: tyxla <[email protected]>
Co-authored-by: ellatrix <[email protected]>
  • Loading branch information
3 people authored and michalczaplinski committed Dec 5, 2024
1 parent 2de57d0 commit b599979
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/block-editor/src/components/iframe/use-scale-canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
* WordPress dependencies
*/
import { useEffect, useRef, useCallback } from '@wordpress/element';
import { useReducedMotion, useResizeObserver } from '@wordpress/compose';
import {
usePrevious,
useReducedMotion,
useResizeObserver,
} from '@wordpress/compose';

/**
* @typedef {Object} TransitionState
Expand Down Expand Up @@ -280,14 +284,15 @@ export function useScaleCanvas( {
transitionFromRef.current = transitionToRef.current;
}, [ iframeDocument ] );

const previousIsZoomedOut = usePrevious( isZoomedOut );
/**
* Runs when zoom out mode is toggled, and sets the startAnimation flag
* so the animation will start when the next useEffect runs. We _only_
* want to animate when the zoom out mode is toggled, not when the scale
* changes due to the container resizing.
*/
useEffect( () => {
if ( ! iframeDocument ) {
if ( ! iframeDocument || previousIsZoomedOut === isZoomedOut ) {
return;
}

Expand All @@ -300,7 +305,7 @@ export function useScaleCanvas( {
return () => {
iframeDocument.documentElement.classList.remove( 'is-zoomed-out' );
};
}, [ iframeDocument, isZoomedOut ] );
}, [ iframeDocument, isZoomedOut, previousIsZoomedOut ] );

/**
* This handles:
Expand Down

0 comments on commit b599979

Please sign in to comment.