-
Notifications
You must be signed in to change notification settings - Fork 25
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
nav: slide #761
nav: slide #761
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after initial run fix
alright – I realized that react-spring perhaps isn't the best library for this task, and i've switched to the latest version of framer-motion that supports react 17 – framer-motion's documentation is far better, the resulting code is easier to read, requires less massaging of app state into a library-friendly form, and the spring physics values it uses actually match up with the ones that figma exports. @urcades these animations look better? I've set the initial animation to not occur on mount, but when the nav's in single-group view, it does still have a slight animate-in when it loads. I think this is because for some reason, when the main nav loads, the Nav component renders once, but when in single-group view, it mounts then re-renders, and due to it no longer being the first render, the animation triggers. I'm not sure what exactly can be done to prevent this, if anyone has an idea let me know. |
Try this:
In classic PM style, I didn't read your code and you might have already attempted this. If the issue is with first load/mount based on route, that's where I would look first. |
@arthyn okay so – with this commit, when in single-group view, upon refresh/URL navigation the sidebar simply doesn't load in lol |
@rcrdlbl We used "hidden" in the mobile view - navigate into the group, the group nav should be shown; navigate into a channel, the group nav should be hidden but retrievable. We're not showing mobile for the demo other than Pocket so feel free to TODO patch around this. |
Alright, i've cut it up – it should be good now |
It seems like if i remove the "hidden" logic from the nav stuff it still works this way? You return to the nav by clicking the little back button next to the group name that shows up in the mobile view, correct? |
I did this to force a route change to get around this problem, yes. |
ui/src/components/Nav/Nav.tsx
Outdated
const flag = useRouteGroup(); | ||
const inChannel = useMatch('/groups/:ship/:name/channels*'); | ||
const firstRender = useIsFirstRender(); | ||
const animationConfig = { | ||
type: 'spring', | ||
stiffness: 2880, | ||
damping: 120, | ||
}; | ||
|
||
useEffect(() => { | ||
if (!firstRender) { | ||
return; | ||
} | ||
|
||
if (isChat) { | ||
useNavStore.getState().navigatePrimary('dm'); | ||
} else if (flag) { | ||
useNavStore.getState().navigatePrimary('group', flag); | ||
} else { | ||
useNavStore.getState().navigatePrimary('main'); | ||
} | ||
}, [flag, firstRender, isMobile, isChat, inChannel]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const flag = useRouteGroup(); | |
const inChannel = useMatch('/groups/:ship/:name/channels*'); | |
const firstRender = useIsFirstRender(); | |
const animationConfig = { | |
type: 'spring', | |
stiffness: 2880, | |
damping: 120, | |
}; | |
useEffect(() => { | |
if (!firstRender) { | |
return; | |
} | |
if (isChat) { | |
useNavStore.getState().navigatePrimary('dm'); | |
} else if (flag) { | |
useNavStore.getState().navigatePrimary('group', flag); | |
} else { | |
useNavStore.getState().navigatePrimary('main'); | |
} | |
}, [flag, firstRender, isMobile, isChat, inChannel]); | |
const flag = useRouteGroup(); | |
const inChannel = useMatch('/groups/:ship/:name/channels*'); | |
const animationConfig = { | |
type: 'spring', | |
stiffness: 2880, | |
damping: 120, | |
}; | |
useEffect(() => { | |
if (isChat) { | |
useNavStore.getState().navigatePrimary('dm'); | |
} else if (flag && isMobile && inChannel) { | |
useNavStore.getState().navigatePrimary('hidden'); | |
} else if (flag) { | |
useNavStore.getState().navigatePrimary('group', flag); | |
} else { | |
useNavStore.getState().navigatePrimary('main'); | |
} | |
}, [flag, isMobile, isChat, inChannel]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
went back and took a second look at the logic. we still need the hidden behavior if you enter a page in a channel. this also corrects the bad logic from earlier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pushed a change that actually seems to get 'hidden' set properly on mobile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
I chose
react-spring
for the animation library as there's two major actively developed NPM packages for spring-based animations, and the other one (framer-motion
) requires react 18+i was originally trying to be clever and use react-spring's useTransition() hook to respond to the route but decided it's better if the logic behind this is as simple as possible.
Improvements to implement
GroupSidebar
losing its group upon returning toall groups
by preventing it from rerendering until the animation finishes