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

Animate the Sidebar Objects Tree view opening #6521

Merged
merged 4 commits into from
Aug 6, 2024
Merged
Changes from 1 commit
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
@@ -1,5 +1,5 @@
import { motion } from 'framer-motion';
import React from 'react';

import { useLocation } from 'react-router-dom';
import { useRecoilValue } from 'recoil';
import { useIcons } from 'twenty-ui';
Expand All @@ -17,6 +17,11 @@ import { useNavigationSection } from '@/ui/navigation/navigation-drawer/hooks/us
import { View } from '@/views/types/View';
import { getObjectMetadataItemViews } from '@/views/utils/getObjectMetadataItemViews';

const navItemsAnimationVariants = {
hidden: { height: 0 },
visible: { height: 'auto' },
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Hello @AliElamir, thank you for contributing.
The animation is not exactly what @Bonapara described in his issue.
When you display your animation slowly, you can see that the children appear instantly and then the parent element height is animated, I feel like you should also animate the height of the children elements to make it feel smoother.

Enregistrement.de.l.ecran.2024-08-05.a.17.06.03.mov

More insights:

  • the animation should also be displayed when we close the menu
  • the opacity also seems to be animated from 0 to 1

Thank you :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @bosiraphael , thank you for your feedback.

I have adjusted the animation based on your comments and pushed the latest changes. It looks right to me now, but please let me know if there are any more adjustments needed. @Bonapara

Thank you!


export const ObjectMetadataNavItems = ({ isRemote }: { isRemote: boolean }) => {
const { toggleNavigationSection, isNavigationSectionOpenState } =
useNavigationSection('Objects' + (isRemote ? 'Remote' : 'Workspace'));
Expand Down Expand Up @@ -103,25 +108,34 @@ export const ObjectMetadataNavItems = ({ isRemote }: { isRemote: boolean }) => {
currentPath === `/objects/${objectMetadataItem.namePlural}`
}
/>
{shouldSubItemsBeDisplayed &&
objectMetadataViews
.sort((viewA, viewB) =>
viewA.key === 'INDEX'
? -1
: viewA.position - viewB.position,
)
.map((view) => (
<NavigationDrawerSubItem
key={view.id}
label={view.name}
to={`/objects/${objectMetadataItem.namePlural}?view=${view.id}`}
active={
currentPathWithSearch ===
`/objects/${objectMetadataItem.namePlural}?view=${view.id}`
}
Icon={getIcon(view.icon)}
/>
))}
{shouldSubItemsBeDisplayed && (
<motion.div
initial="hidden"
animate="visible"
exit="hidden"
variants={navItemsAnimationVariants}
transition={{ duration: 0.3 }}
>
{objectMetadataViews
.sort((viewA, viewB) =>
viewA.key === 'INDEX'
? -1
: viewA.position - viewB.position,
)
.map((view) => (
<NavigationDrawerSubItem
key={view.id}
label={view.name}
to={`/objects/${objectMetadataItem.namePlural}?view=${view.id}`}
active={
currentPathWithSearch ===
`/objects/${objectMetadataItem.namePlural}?view=${view.id}`
}
Icon={getIcon(view.icon)}
/>
))}
</motion.div>
)}
</React.Fragment>
);
})}
Expand Down
Loading