Skip to content

Commit

Permalink
Redo keep scale constant after zoomed out
Browse files Browse the repository at this point in the history
  • Loading branch information
stokesman committed Aug 5, 2024
1 parent b1acf84 commit 762182c
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions packages/block-editor/src/components/iframe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,22 @@ function Iframe( {

const isZoomedOut = scale !== 1;
const priorContainerWidth = useRef();
const isScaleFinal = useRef( false );
useEffect( () => {
if ( isZoomedOut ) {
return () => {
isScaleFinal.current = false;
const { documentElement, defaultView } = iframeDocument;
documentElement.classList.remove( 'is-zoomed-out' );
defaultView.frameElement.style.removeProperty(
'--wp-block-editor-iframe-zoom-out-scale'
);
defaultView.frameElement.style.removeProperty(
'--wp-block-editor-iframe-zoom-out-inset'
);
};
}
}, [ isZoomedOut ] );

useEffect( () => {
if ( ! isZoomedOut ) {
Expand Down Expand Up @@ -257,7 +273,7 @@ function Iframe( {
useEffect( () => cleanup, [ cleanup ] );

useEffect( () => {
if ( ! iframeDocument || ! isZoomedOut ) {
if ( ! iframeDocument || ! isZoomedOut || isScaleFinal.current ) {
return;
}
const frameInlineWidth = frameSize * 2;
Expand All @@ -276,16 +292,6 @@ function Iframe( {
'--wp-block-editor-iframe-zoom-out-inset',
`${ frameSize }px`
);

return () => {
documentElement.classList.remove( 'is-zoomed-out' );
defaultView.frameElement.style.removeProperty(
'--wp-block-editor-iframe-zoom-out-scale'
);
defaultView.frameElement.style.removeProperty(
'--wp-block-editor-iframe-zoom-out-inset'
);
};
}, [ containerWidth, frameSize, iframeDocument, isZoomedOut ] );

const { marginLeft, marginRight, ...styleWithoutInlineMargins } =
Expand Down Expand Up @@ -346,6 +352,12 @@ function Iframe( {
);
}
} }
onTransitionEnd={ ( event ) => {
if ( event.propertyName === 'transform' && isZoomedOut ) {
isScaleFinal.current = true;
}
props.onTransitionEnd?.( event );
} }
>
{ iframeDocument &&
createPortal(
Expand Down

0 comments on commit 762182c

Please sign in to comment.