Skip to content

Commit

Permalink
Move scrollHeight to animateFrom state
Browse files Browse the repository at this point in the history
  • Loading branch information
ajlende committed Nov 25, 2024
1 parent 0ff92b5 commit 92e0e52
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/block-editor/src/components/iframe/use-scale-canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ function calculateScale( {
/**
* Compute the next scrollTop position after scaling the iframe content.
*
* @param {number} scrollHeight Scaled height of the current iframe content.
* @param {Object} transitionFrom The starting point of the transition
* @param {Object} transitionTo The ending state of the transition
* @return {number} The next scrollTop position after scaling the iframe content.
*/
function computeScrollTopNext( scrollHeight, transitionFrom, transitionTo ) {
function computeScrollTopNext( transitionFrom, transitionTo ) {
const {
clientHeight: prevClientHeight,
frameSize: prevFrameSize,
scaleValue: prevScale,
scrollTop: scrollTop,
scrollTop,
scrollHeight,
} = transitionFrom;
const { clientHeight, frameSize, scaleValue } = transitionTo;
// Step 0: Start with the current scrollTop.
Expand Down Expand Up @@ -174,6 +174,7 @@ export function useScaleCanvas( {
frameSize,
clientHeight: 0,
scrollTop: 0,
scrollHeight: 0,
} );

/**
Expand All @@ -184,6 +185,7 @@ export function useScaleCanvas( {
frameSize,
clientHeight: 0,
scrollTop: 0,
scrollHeight: 0,
} );

/**
Expand Down Expand Up @@ -384,14 +386,15 @@ export function useScaleCanvas( {
transitionFrom.current.clientHeight ?? clientHeight;
transitionFrom.current.scrollTop =
iframeDocument.documentElement.scrollTop;
transitionFrom.current.scrollHeight =
iframeDocument.documentElement.scrollHeight;

transitionTo.current = {
scaleValue,
frameSize,
clientHeight,
};
transitionTo.current.scrollTop = computeScrollTopNext(
iframeDocument.documentElement.scrollHeight,
transitionFrom.current,
transitionTo.current
);
Expand Down

0 comments on commit 92e0e52

Please sign in to comment.