Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block Editor: Animate useScaleCanvas() only when toggling zoomed out mode #67481

Merged
merged 1 commit into from
Dec 2, 2024
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