Skip to content

Commit

Permalink
Block Editor: useMovingAnimation: Avoid initial transform animation (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth authored May 22, 2020
1 parent 6675dc5 commit a6b89aa
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions packages/block-editor/src/components/use-moving-animation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,13 @@ function useMovingAnimation(
}
}, [ triggeredAnimation ] );
useLayoutEffect( () => {
if ( ! previous ) {
return;
}

scrollContainer.current = getScrollContainer( ref.current );
if ( prefersReducedMotion ) {
if ( adjustScrolling && scrollContainer.current && previous ) {
if ( adjustScrolling && scrollContainer.current ) {
// if the animation is disabled and the scroll needs to be adjusted,
// just move directly to the final scroll position
ref.current.style.transform = 'none';
Expand All @@ -95,14 +99,13 @@ function useMovingAnimation(
ref.current.style.transform = 'none';
const destination = getAbsolutePosition( ref.current );
const newTransform = {
x: previous ? previous.left - destination.left : 0,
y: previous ? previous.top - destination.top : 0,
scrollTop:
previous && scrollContainer.current
? scrollContainer.current.scrollTop -
previous.top +
destination.top
: 0,
x: previous.left - destination.left,
y: previous.top - destination.top,
scrollTop: scrollContainer.current
? scrollContainer.current.scrollTop -
previous.top +
destination.top
: 0,
};
ref.current.style.transform =
newTransform.x === 0 && newTransform.y === 0
Expand Down

0 comments on commit a6b89aa

Please sign in to comment.