Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading