@@ -156,6 +156,8 @@ export function useScaleCanvas( {
156156 `${ scaleContainerWidth } px`
157157 ) ;
158158
159+ let onZoomOutTransitionEnd = ( ) => { } ;
160+
159161 if ( isAnimatingZoomOut ) {
160162 // Unscaled height of the current iframe container.
161163 const clientHeight = iframeDocument . documentElement . clientHeight ;
@@ -248,30 +250,28 @@ export function useScaleCanvas( {
248250 scaleValue
249251 ) ;
250252
251- function onZoomOutTransitionEnd ( ) {
252- if ( isAnimatingZoomOut ) {
253- isAnimatingRef . current = false ;
254- iframeDocument . documentElement . classList . remove (
255- 'zoom-out-animation'
256- ) ;
257- setIsAnimatingZoomOut ( false ) ;
258-
259- // Update previous values.
260- prevClientHeightRef . current = clientHeight ;
261- prevFrameSizeRef . current = frameSize ;
262- prevScaleRef . current = scale ;
263-
264- // Set the final scroll position that was just animated to.
265- iframeDocument . documentElement . scrollTop = scrollTopNext ;
266-
267- iframeDocument . documentElement . style . removeProperty (
268- '--wp-block-editor-iframe-zoom-out-scroll-top'
269- ) ;
270- iframeDocument . documentElement . style . removeProperty (
271- '--wp-block-editor-iframe-zoom-out-scroll-top-next'
272- ) ;
273- }
274- }
253+ onZoomOutTransitionEnd = ( ) => {
254+ isAnimatingRef . current = false ;
255+ iframeDocument . documentElement . classList . remove (
256+ 'zoom-out-animation'
257+ ) ;
258+ setIsAnimatingZoomOut ( false ) ;
259+
260+ // Update previous values.
261+ prevClientHeightRef . current = clientHeight ;
262+ prevFrameSizeRef . current = frameSize ;
263+ prevScaleRef . current = scale ;
264+
265+ // Set the final scroll position that was just animated to.
266+ iframeDocument . documentElement . scrollTop = scrollTopNext ;
267+
268+ iframeDocument . documentElement . style . removeProperty (
269+ '--wp-block-editor-iframe-zoom-out-scroll-top'
270+ ) ;
271+ iframeDocument . documentElement . style . removeProperty (
272+ '--wp-block-editor-iframe-zoom-out-scroll-top-next'
273+ ) ;
274+ } ;
275275
276276 if ( prefersReducedMotion ) {
277277 onZoomOutTransitionEnd ( ) ;
@@ -285,26 +285,29 @@ export function useScaleCanvas( {
285285 }
286286
287287 return ( ) => {
288- // HACK: Skipping cleanup because it causes issues with the zoom out
289- // animation. More refactoring is needed to fix this properly.
290- // iframeDocument.documentElement.style.removeProperty(
291- // '--wp-block-editor-iframe-zoom-out-scale'
292- // );
293- // iframeDocument.documentElement.style.removeProperty(
294- // '--wp-block-editor-iframe-zoom-out-frame-size'
295- // );
296- // iframeDocument.documentElement.style.removeProperty(
297- // '--wp-block-editor-iframe-zoom-out-content-height'
298- // );
299- // iframeDocument.documentElement.style.removeProperty(
300- // '--wp-block-editor-iframe-zoom-out-inner-height'
301- // );
302- // iframeDocument.documentElement.style.removeProperty(
303- // '--wp-block-editor-iframe-zoom-out-container-width'
304- // );
305- // iframeDocument.documentElement.style.removeProperty(
306- // '--wp-block-editor-iframe-zoom-out-scale-container-width'
307- // );
288+ iframeDocument . documentElement . style . removeProperty (
289+ '--wp-block-editor-iframe-zoom-out-scale'
290+ ) ;
291+ iframeDocument . documentElement . style . removeProperty (
292+ '--wp-block-editor-iframe-zoom-out-frame-size'
293+ ) ;
294+ iframeDocument . documentElement . style . removeProperty (
295+ '--wp-block-editor-iframe-zoom-out-content-height'
296+ ) ;
297+ iframeDocument . documentElement . style . removeProperty (
298+ '--wp-block-editor-iframe-zoom-out-inner-height'
299+ ) ;
300+ iframeDocument . documentElement . style . removeProperty (
301+ '--wp-block-editor-iframe-zoom-out-container-width'
302+ ) ;
303+ iframeDocument . documentElement . style . removeProperty (
304+ '--wp-block-editor-iframe-zoom-out-scale-container-width'
305+ ) ;
306+
307+ iframeDocument . documentElement . removeEventListener (
308+ 'transitionend' ,
309+ onZoomOutTransitionEnd
310+ ) ;
308311 } ;
309312 } , [
310313 isAnimatingZoomOut ,
0 commit comments