Commit 168e3092 authored by isstuev's avatar isstuev

animation fix

parent 87ab7a9e
import { Box, Flex, Text, Icon, VStack, useColorModeValue } from '@chakra-ui/react'; import { Box, Flex, Text, Icon, VStack, useColorModeValue } from '@chakra-ui/react';
import { AnimatePresence, animate, motion, useMotionValue } from 'framer-motion'; import { animate, motion, useMotionValue } from 'framer-motion';
import React, { useCallback } from 'react'; import React, { useCallback } from 'react';
import appConfig from 'configs/app/config'; import appConfig from 'configs/app/config';
...@@ -16,17 +16,19 @@ const NavigationMobile = () => { ...@@ -16,17 +16,19 @@ const NavigationMobile = () => {
const [ openedGroupIndex, setOpenedGroupIndex ] = React.useState(-1); const [ openedGroupIndex, setOpenedGroupIndex ] = React.useState(-1);
const x = useMotionValue(0); const mainX = useMotionValue(0);
const subX = useMotionValue(250);
const onGroupItemOpen = (index: number) => () => { const onGroupItemOpen = (index: number) => () => {
animate(x, -250);
setOpenedGroupIndex(index); setOpenedGroupIndex(index);
animate(mainX, -250, { ease: 'easeInOut' });
animate(subX, 0, { ease: 'easeInOut' });
}; };
const onGroupItemClose = useCallback(() => { const onGroupItemClose = useCallback(() => {
animate(x, 0); animate(mainX, 0, { ease: 'easeInOut' });
setOpenedGroupIndex(-1); animate(subX, 250, { ease: 'easeInOut', onComplete: () => setOpenedGroupIndex(-1) });
}, [ x ]); }, [ mainX, subX ]);
const isAuth = Boolean(cookies.get(cookies.NAMES.API_TOKEN)); const isAuth = Boolean(cookies.get(cookies.NAMES.API_TOKEN));
const hasAccount = appConfig.isAccountSupported && isAuth; const hasAccount = appConfig.isAccountSupported && isAuth;
...@@ -39,8 +41,7 @@ const NavigationMobile = () => { ...@@ -39,8 +41,7 @@ const NavigationMobile = () => {
<Box <Box
as={ motion.nav } as={ motion.nav }
mt={ 6 } mt={ 6 }
style={{ x }} style={{ x: mainX }}
transitionDuration="100ms"
> >
<VStack <VStack
w="100%" w="100%"
...@@ -61,26 +62,20 @@ const NavigationMobile = () => { ...@@ -61,26 +62,20 @@ const NavigationMobile = () => {
<Box <Box
as={ motion.nav } as={ motion.nav }
mt={ 6 } mt={ 6 }
style={{ x }} style={{ x: mainX }}
transitionDuration="100ms"
> >
<VStack as="ul" spacing="1" alignItems="flex-start"> <VStack as="ul" spacing="1" alignItems="flex-start">
{ accountNavItems.map((item) => <NavLink key={ item.text } { ...item }/>) } { accountNavItems.map((item) => <NavLink key={ item.text } { ...item }/>) }
</VStack> </VStack>
</Box> </Box>
) } ) }
<AnimatePresence>
{ openedGroupIndex >= 0 && ( { openedGroupIndex >= 0 && (
<Box <Box
as={ motion.nav } as={ motion.nav }
mt={ 6 } mt={ 6 }
position="absolute" position="absolute"
top={ 0 } top={ 0 }
initial={{ x: 250 }} style={{ x: subX }}
animate={{ x: 0 }}
exit={{ x: 250 }}
transitionDuration="100ms"
transitionTimingFunction="linear"
key="sub" key="sub"
> >
<VStack <VStack
...@@ -97,7 +92,6 @@ const NavigationMobile = () => { ...@@ -97,7 +92,6 @@ const NavigationMobile = () => {
</VStack> </VStack>
</Box> </Box>
) } ) }
</AnimatePresence>
</Box> </Box>
<NavFooter hasAccount={ hasAccount }/> <NavFooter hasAccount={ hasAccount }/>
</> </>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment