Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
4192156
Midway commit. Scaling out is broken
jeryj Oct 30, 2024
5bb30a1
Fix zoom in animation
jeryj Oct 30, 2024
22186f2
Fix scaling by preserving CSS properites
jeryj Oct 30, 2024
afd8ca3
Prevent reflow from removing and re adding scrollbar in animation
jeryj Oct 30, 2024
123d647
Only rerun zoom out use effects if zoom out has changed.
jeryj Oct 31, 2024
fd15912
Allow all CSS vars to update when scale changes
jeryj Oct 31, 2024
3a3e1ad
Midway commit. Math is wrong for addressing top/bottom exceptions
jeryj Oct 31, 2024
e16a2a8
Remove usePrevious usage
ajlende Oct 31, 2024
e4bf2dd
Add prefers-reduced-motion to setTimeout delay
ajlende Nov 5, 2024
8d767b4
WIP Working zoom without frame size
ajlende Nov 5, 2024
f37547d
Account for changes to client height when determining edge threshold
jeryj Nov 6, 2024
5cce3b2
Zoom to center unless it will reveal top or bottom
jeryj Nov 6, 2024
8b9c693
Account for a top threshold when zooming in and out
jeryj Nov 6, 2024
adea71c
Clean up math and add comments
ajlende Nov 6, 2024
fcc49f4
Add event listener instead of timeout
ajlende Nov 6, 2024
08247f0
Fix reduced motion
ajlende Nov 6, 2024
ec73741
Remove timeout ref
ajlende Nov 6, 2024
6996c1b
Refactor callback as separate effect
ajlende Nov 6, 2024
c79718e
Fix JSDoc comment
ajlende Nov 6, 2024
77559a8
Try to add back useEffect cleanups
ajlende Nov 6, 2024
9fa40e2
Initialize prevClientHeight in the useEffect
ajlende Nov 7, 2024
f0fe6ab
use useReducedMotion
jeryj Nov 7, 2024
0ccd9e5
Add test for zoom in/out location
jeryj Nov 7, 2024
e88ee83
Hack to fix reduced motion
ajlende Nov 8, 2024
14b9f63
Clean up the frameSizeValue and scaleValue calculations
ajlende Nov 8, 2024
f9ab519
Replace TODO comments with HACK comments
ajlende Nov 8, 2024
c5d3445
Add cleanup for raf
ajlende Nov 8, 2024
534485a
Simplify CSS diff for 6.7 review
ajlende Nov 8, 2024
8b912e4
Add one more HACK comment
ajlende Nov 8, 2024
32ae736
Do not allow scrollTopNext to be smaller than 0
jeryj Nov 11, 2024
73e032e
Fix zoom-out.spec.js
ajlende Nov 19, 2024
857ca64
Disable errant react-compiler eslint rule
ajlende Nov 25, 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
Midway commit. Math is wrong for addressing top/bottom exceptions
  • Loading branch information
jeryj authored and ajlende committed Nov 25, 2024
commit 3a3e1ad7302e0e35e5a49ce99bc26426bf49e450
29 changes: 25 additions & 4 deletions packages/block-editor/src/components/iframe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,29 @@ function Iframe( {
prevContainerHeightRef.current / 2
);

// // Convert the zoomed in value to the new scale.
// // Use Math.round to avoid subpixel scrolling which would effectively result in a Math.floor.
const scrollTopNext = Math.round(
// Convert the zoomed in value to the new scale.
// Use Math.round to avoid subpixel scrolling which would effectively result in a Math.floor.
let scrollTopNext = Math.round(
( scrollTopOriginal + containerHeight / 2 ) * scaleValue +
frameSizeValue -
containerHeight / 2
);

const edgeThreshold = prevContainerHeightRef.current / 2;
const maxScrollPosition =
contentHeight - prevContainerHeightRef.current - frameSizeValue * 2;

const scaleToTop = scrollTopOriginal - edgeThreshold <= 0;
const scaleToBottom =
scrollTopOriginal - maxScrollPosition - edgeThreshold <= 0;

if ( scaleToTop ) {
scrollTopNext = 0;
} else if ( scaleToBottom ) {
// Not sure on this
scrollTopNext = maxScrollPosition * scaleValue;
}

iframeDocument.documentElement.style.setProperty(
'--wp-block-editor-iframe-zoom-out-scroll-top',
`${ scrollTop }px`
Expand All @@ -387,7 +402,13 @@ function Iframe( {

iframeDocument.documentElement.scrollTop = scrollTopNext;
}, 400 ); // 400ms should match the animation speed used in components/iframe/content.scss
}, [ scaleValue, frameSizeValue, containerHeight, iframeDocument ] );
}, [
scaleValue,
frameSizeValue,
containerHeight,
iframeDocument,
contentHeight,
] );

// Toggle zoom out CSS Classes only when zoom out mode changes. We could add these into the useEffect
// that controls settings the CSS variables, but then we would need to do more work to ensure we're
Expand Down