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

Try restoring the site editor animation #51956

Merged
merged 9 commits into from
Jul 4, 2023
81 changes: 38 additions & 43 deletions packages/edit-site/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,66 +224,61 @@ export default function Layout() {
<AnimatePresence initial={ false }>
{ isEditorPage && isEditing && (
<NavigableRegion
key="header"
className="edit-site-layout__header"
ariaLabel={ __( 'Editor top bar' ) }
as={ motion.div }
variants={ {
isDistractionFree: { opacity: 0 },
isDistractionFreeHovering: { opacity: 1 },
view: { opacity: 1 },
edit: { opacity: 1 },
isDistractionFree: { opacity: 0, y: 0 },
isDistractionFreeHovering: {
opacity: 1,
y: 0,
},
view: { opacity: 1, y: '-100%' },
edit: { opacity: 1, y: 0 },
} }
exit={ {
y: '-100%',
} }
initial={ {
opacity: isDistractionFree ? 1 : 0,
jeryj marked this conversation as resolved.
Show resolved Hide resolved
y: isDistractionFree ? 0 : '-100%',
} }
transition={ {
type: 'tween',
duration: disableMotion ? 0 : 0.2,
ease: 'easeOut',
} }
>
{ isEditing && <Header /> }
<Header />
</NavigableRegion>
) }
</AnimatePresence>
</motion.div>

<div className="edit-site-layout__content">
<AnimatePresence initial={ false }>
Copy link
Contributor

Choose a reason for hiding this comment

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

<AnimatePresence /> is only needed when we need to animate removing an element. We're not removing it from the DOM, just hiding it from user interactions, so we don't need to use this anymore.

{
<motion.div
initial={ {
opacity: 0,
} }
animate={
showSidebar
? { opacity: 1, display: 'block' }
: {
opacity: 0,
transitionEnd: {
display: 'none',
},
}
}
exit={ {
opacity: 0,
} }
transition={ {
type: 'tween',
duration:
// Disable transition in mobile to emulate a full page transition.
disableMotion || isMobileViewport
? 0
: ANIMATION_DURATION,
ease: 'easeOut',
} }
className="edit-site-layout__sidebar"
>
<NavigableRegion
ariaLabel={ __( 'Navigation' ) }
>
<Sidebar />
</NavigableRegion>
</motion.div>
}
</AnimatePresence>
<motion.div
// The sidebar is needed for routing on mobile
// (https://github.com/WordPress/gutenberg/pull/51558/files#r1231763003),
// so we can't remove the element entirely. Using `inert` will make
// it inaccessible to screen readers and keyboard navigation.
inert={ showSidebar ? undefined : 'inert' }
animate={ { opacity: showSidebar ? 1 : 0 } }
transition={ {
type: 'tween',
duration:
// Disable transition in mobile to emulate a full page transition.
disableMotion || isMobileViewport
? 0
: ANIMATION_DURATION,
ease: 'easeOut',
} }
className="edit-site-layout__sidebar"
>
<NavigableRegion ariaLabel={ __( 'Navigation' ) }>
<Sidebar />
</NavigableRegion>
</motion.div>

<SavePanel />

Expand Down