Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Site Editor Animation: We have a mismatch of animation when toggling the site editor sidebar #48630

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
import type { ForwardedRef } from 'react';
// eslint-disable-next-line no-restricted-imports
import { motion, MotionProps } from 'framer-motion';
import { css } from '@emotion/react';

/**
Expand All @@ -17,8 +16,7 @@ import {
useRef,
useId,
} from '@wordpress/element';
import { useReducedMotion, useMergeRefs } from '@wordpress/compose';
import { isRTL } from '@wordpress/i18n';
import { useMergeRefs } from '@wordpress/compose';
import { escapeAttribute } from '@wordpress/escape-html';

/**
Expand All @@ -34,20 +32,8 @@ import { View } from '../../view';
import { NavigatorContext } from '../context';
import type { NavigatorScreenProps } from '../types';

const animationEnterDelay = 0;
const animationEnterDuration = 0.14;
const animationExitDuration = 0.14;
const animationExitDelay = 0;

// Props specific to `framer-motion` can't be currently passed to `NavigatorScreen`,
// as some of them would overlap with HTML props (e.g. `onAnimationStart`, ...)
type Props = Omit<
WordPressComponentProps< NavigatorScreenProps, 'div', false >,
keyof MotionProps
>;

function UnconnectedNavigatorScreen(
props: Props,
props: WordPressComponentProps< NavigatorScreenProps, 'div', false >,
forwardedRef: ForwardedRef< any >
) {
const screenId = useId();
Expand All @@ -56,7 +42,6 @@ function UnconnectedNavigatorScreen(
'NavigatorScreen'
);

const prefersReducedMotion = useReducedMotion();
const { location, match, addScreen, removeScreen } =
useContext( NavigatorContext );
const isMatch = match === screenId;
Expand Down Expand Up @@ -151,62 +136,10 @@ function UnconnectedNavigatorScreen(
return null;
}

if ( prefersReducedMotion ) {
return (
<View
ref={ mergedWrapperRef }
className={ classes }
{ ...otherProps }
>
{ children }
</View>
);
}

const animate = {
opacity: 1,
transition: {
delay: animationEnterDelay,
duration: animationEnterDuration,
ease: 'easeInOut',
},
x: 0,
};
const initial = {
opacity: 0,
x:
( isRTL() && location.isBack ) || ( ! isRTL() && ! location.isBack )
? 50
: -50,
};
const exit = {
delay: animationExitDelay,
opacity: 0,
x:
( ! isRTL() && location.isBack ) || ( isRTL() && ! location.isBack )
? 50
: -50,
transition: {
duration: animationExitDuration,
ease: 'easeInOut',
},
};

const animatedProps = {
animate,
exit,
initial,
};

return (
<motion.div
ref={ mergedWrapperRef }
className={ classes }
{ ...otherProps }
{ ...animatedProps }
>
<View ref={ mergedWrapperRef } className={ classes } { ...otherProps }>
{ children }
</motion.div>
</View>
);
}

Expand Down
12 changes: 2 additions & 10 deletions packages/edit-site/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ export default function Layout() {
const canvasPadding = isMobileViewport ? 0 : 24;
const showSidebar =
( isMobileViewport && ! isListPage ) ||
( ! isMobileViewport && ( canvasMode === 'view' || ! isEditorPage ) );
! isMobileViewport ||
! isEditorPage;
Comment on lines +95 to +96
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to test how this affects performance. Rendering a component when we don't use it doesn't seem like the right way to do it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the reason I pinged you, wondered about this. But the only other way we can achieve this look is by taking this approach, or delaying the animation which will definitely make the UI feel slow.

I would like to test the performance for you, but have no idea how I would go about that. Could you point me in the right direction there? :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to rendering an unused component, having it in the DOM could have some a11y impacts could it not?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasmussen @jameskoster This in combination with the y-axis enter and exit animation having to return makes me think this'll just have to stay the way it is.

const showCanvas =
( isMobileViewport && isEditorPage && canvasMode === 'edit' ) ||
! isMobileViewport ||
Expand Down Expand Up @@ -182,15 +183,6 @@ export default function Layout() {
{ showSidebar && (
<ResizableBox
as={ motion.div }
initial={ {
opacity: 0,
} }
animate={ {
opacity: 1,
} }
exit={ {
opacity: 0,
} }
transition={ {
type: 'tween',
duration:
Expand Down