Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
af08ecc
Midway commit. Scaling out is broken
jeryj Oct 30, 2024
c83c99f
Fix zoom in animation
jeryj Oct 30, 2024
ec58902
Fix scaling by preserving CSS properites
jeryj Oct 30, 2024
6582cce
Prevent reflow from removing and re adding scrollbar in animation
jeryj Oct 30, 2024
ce9497e
Only rerun zoom out use effects if zoom out has changed.
jeryj Oct 31, 2024
26d9e3a
Allow all CSS vars to update when scale changes
jeryj Oct 31, 2024
3947ab0
Midway commit. Math is wrong for addressing top/bottom exceptions
jeryj Oct 31, 2024
cb47e82
Remove usePrevious usage
ajlende Oct 31, 2024
bc8cca6
Add prefers-reduced-motion to setTimeout delay
ajlende Nov 5, 2024
578c923
WIP Working zoom without frame size
ajlende Nov 5, 2024
d2c16a6
Account for changes to client height when determining edge threshold
jeryj Nov 6, 2024
0faf418
Zoom to center unless it will reveal top or bottom
jeryj Nov 6, 2024
ab8038e
Account for a top threshold when zooming in and out
jeryj Nov 6, 2024
ba32f99
Clean up math and add comments
ajlende Nov 6, 2024
0b640ee
Add event listener instead of timeout
ajlende Nov 6, 2024
6a3f7a0
Fix reduced motion
ajlende Nov 6, 2024
55df6fe
Remove timeout ref
ajlende Nov 6, 2024
7ba67b2
Refactor callback as separate effect
ajlende Nov 6, 2024
2dc137f
Try to add back useEffect cleanups
ajlende Nov 6, 2024
3eabcf5
Initialize prevClientHeight in the useEffect
ajlende Nov 7, 2024
8b8c206
use useReducedMotion
jeryj Nov 7, 2024
23bd453
Add test for zoom in/out location
jeryj Nov 7, 2024
8cbe2be
Hack to fix reduced motion
ajlende Nov 8, 2024
4c9543e
Clean up the frameSizeValue and scaleValue calculations
ajlende Nov 8, 2024
4e87729
Replace TODO comments with HACK comments
ajlende Nov 8, 2024
17f50d5
Add cleanup for raf
ajlende Nov 8, 2024
b049f4b
Simplify CSS diff for 6.7 review
ajlende Nov 8, 2024
61a0de9
Add one more HACK comment
ajlende Nov 8, 2024
ac52f2d
Do not allow scrollTopNext to be smaller than 0
jeryj Nov 11, 2024
6b23a30
Fix zoom-out.spec.js
ajlende Nov 19, 2024
fd74dc4
Move 6.7 iframe scaling work to trunk
jeryj Nov 13, 2024
bfaf7e4
Move calculations to useScaleCanvas hook
jeryj Nov 13, 2024
cc28155
Rename scaleValue to scale
jeryj Nov 13, 2024
d407ee6
Rename frameSizeValue to frameSize
jeryj Nov 13, 2024
c8f2cc7
Remove iframeWindowInnerHeight
jeryj Nov 13, 2024
7903702
Remove unused window resize ref
jeryj Nov 13, 2024
72f5785
Refactor CSS
jeryj Nov 13, 2024
53d8f6f
Move animation to state
jeryj Nov 13, 2024
a25f7da
Fix scaling the canvas when sidebars open/close
jeryj Nov 13, 2024
5fcd9c1
Recalculate scale before exiting scaled canvas to prevent snapping ef…
jeryj Nov 14, 2024
1c5d7d5
CSS linting
jeryj Nov 14, 2024
96d62ab
Move code into useScaleCanvas that isn't necessary in iframe index
jeryj Nov 14, 2024
ec37f26
Move resize listeners into useScaledCanvas
jeryj Nov 14, 2024
28cff48
Combine into one useEffect
jeryj Nov 15, 2024
28ded6a
Add useEffect cleanup
jeryj Nov 15, 2024
1dbdc82
Fix accidental setting prevScaleRef to scale instead of scaleValue
jeryj Nov 19, 2024
cf8ffde
Switch to animations api
jeryj Nov 19, 2024
f338821
Reduce rerenders by removing isAnimatingZoomOut state and relying jus…
jeryj Nov 19, 2024
5c93399
Refactor to set scale and frame size on transition end
jeryj Nov 19, 2024
ff03e1e
Add reverse animation if zoom state is toggled quickly
jeryj Nov 20, 2024
65bd82e
Refactor step 1 of reverse animation with transitionTo and transition…
jeryj Nov 20, 2024
f236641
Finish refactor of transitionTo/From refs
jeryj Nov 20, 2024
83ee4c5
Refactor: computeScrollTopNext
jeryj Nov 20, 2024
32b24e5
Refactor: getAnimationKeyframes
jeryj Nov 20, 2024
1407f8f
Add missing dependency
jeryj Nov 20, 2024
d5402bc
Refactor: create startZoomOutAnimation and rename scrollTopNext to tr…
jeryj Nov 20, 2024
fc6b4ee
Remove unneeded variables
jeryj Nov 20, 2024
2325135
Move CSS back to original location, as it no longer needs to be moved
jeryj Nov 21, 2024
b41d282
Add comments
jeryj Nov 21, 2024
0ff92b5
Fix eslint error
ajlende Nov 25, 2024
92e0e52
Move scrollHeight to animateFrom state
ajlende Nov 25, 2024
fb16c4f
Update JSDoc
ajlende Nov 25, 2024
4076a7b
Rename ref variables to use "Ref" suffix
ajlende Nov 26, 2024
798549e
Comment style guide
ajlende Nov 26, 2024
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
Prev Previous commit
Next Next commit
Finish refactor of transitionTo/From refs
  • Loading branch information
jeryj authored and ajlende committed Nov 25, 2024
commit f236641bde338a9a24b2c011bb17eff16f6dd5b0
36 changes: 11 additions & 25 deletions packages/block-editor/src/components/iframe/use-scale-canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,6 @@ export function useScaleCanvas( {
} )
: scale;

const prevScaleRef = useRef( scaleValue );
const prevFrameSizeRef = useRef( frameSize );
const prevClientHeightRef = useRef( /* Initialized in the useEffect. */ );
const prevScrollTop = useRef( 0 );
const scrollTopNextRef = useRef( 0 );
const clientHeightRef = useRef( 0 );

const transitionFrom = useRef( {
scaleValue,
frameSize,
Expand Down Expand Up @@ -114,16 +107,16 @@ export function useScaleCanvas( {
return;
}

if ( isAutoScaled && prevScaleRef.current !== 1 ) {
if ( isAutoScaled && transitionFrom.current.scaleValue !== 1 ) {
// We need to update the appropriate scale to exit from. If sidebars have been opened since setting the
// original scale, we will snap to a much smaller scale due to the scale container changing size when exiting.
// We use containerWidth as the divisor, as scaleContainerWidth will always match the containerWidth when
// exiting.
prevScaleRef.current = calculateScale( {
transitionFrom.current.scaleValue = calculateScale( {
containerWidth,
maxContainerWidth,
scaleContainerWidth: containerWidth,
frameSize: prevFrameSizeRef.current,
frameSize: transitionFrom.current.frameSize,
} );
}

Expand All @@ -147,7 +140,6 @@ export function useScaleCanvas( {
);

const clientHeight = iframeDocument.documentElement.clientHeight;
clientHeightRef.current = clientHeight;
iframeDocument.documentElement.style.setProperty(
'--wp-block-editor-iframe-zoom-out-inner-height',
`${ clientHeight }px`
Expand All @@ -172,6 +164,8 @@ export function useScaleCanvas( {
* - after the animation is complete, remove the fixed positioning
* and set the scroll position that keeps everything centered
*/

const prevScale = transitionFrom.current.scaleValue;
if ( startAnimationRef.current ) {
// Don't allow a new transition to start again unless it was started by the zoom out mode changing.
startAnimationRef.current = false;
Expand All @@ -192,20 +186,17 @@ export function useScaleCanvas( {

// Only start a new animation if the scale has changed. Otherwise we're just updating the CSS variables
// or reversing the animation.
else if ( scaleValue !== prevScaleRef.current ) {
else if ( scaleValue !== prevScale ) {
// Scaled height of the current iframe content.
const scrollHeight =
iframeDocument.documentElement.scrollHeight;

// Previous scale value.
const prevScale = prevScaleRef.current;

// Unscaled size of the previous padding around the iframe content.
const prevFrameSize = prevFrameSizeRef.current;
const prevFrameSize = transitionFrom.current.frameSize;

// Unscaled height of the previous iframe container.
const prevClientHeight =
prevClientHeightRef.current ?? clientHeightRef.current;
transitionFrom.current.clientHeight ?? clientHeight;
// We can't trust the set value from contentHeight, as it was measured
// before the zoom out mode was changed. After zoom out mode is changed,
// appenders may appear or disappear, so we need to get the height from
Expand All @@ -215,7 +206,6 @@ export function useScaleCanvas( {
// is toggled, as the bottom bar about selecting the template is
// added/removed when toggling zoom out mode.
const scrollTop = iframeDocument.documentElement.scrollTop;
prevScrollTop.current = scrollTop;
// Step 0: Start with the current scrollTop.
let scrollTopNext = scrollTop;
// Step 1: Undo the effects of the previous scale and frame around the
Expand Down Expand Up @@ -255,7 +245,6 @@ export function useScaleCanvas( {
Math.max( 0, maxScrollTop )
)
);
scrollTopNextRef.current = scrollTopNext;

iframeDocument.documentElement.style.setProperty(
'--wp-block-editor-iframe-zoom-out-scroll-top',
Expand Down Expand Up @@ -325,12 +314,6 @@ export function useScaleCanvas( {
'zoom-out-animation'
);

// Update previous values.
prevClientHeightRef.current =
transitionTo.current.clientHeight;
prevFrameSizeRef.current = transitionTo.current.frameSize;
prevScaleRef.current = transitionTo.current.scaleValue;

// Set the final scroll position that was just animated to.
iframeDocument.documentElement.scrollTop =
transitionTo.current.scrollTopNext;
Expand All @@ -341,6 +324,9 @@ export function useScaleCanvas( {
iframeDocument.documentElement.style.removeProperty(
'--wp-block-editor-iframe-zoom-out-scroll-top-next'
);

// Update previous values.
transitionFrom.current = transitionTo.current;
};

if ( prefersReducedMotion ) {
Expand Down