-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat: 내비게이션 바 애니메이션 추가 #435
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7e170c4
refacor: NavItem 컴포넌트 분리
WaiNaat aa372c5
refactor: NavLink 제거
WaiNaat 736b3ff
feat: Navbar 애니메이션 추가
WaiNaat 6a9d46f
refactor: Navbar RootTemplate으로 이동
WaiNaat 5ae36f6
refactor: 페이지 로딩 이후에 Navbar도 바뀜
WaiNaat fb36f39
refactor: 컴포넌트 안에서 컴포넌트 정의하는 문제 수정
WaiNaat e1f281c
refactor: 불필요한 non-null assertion, useMemo 제거
WaiNaat f29883a
refactor: exhaustive deps 문제 해결
WaiNaat df8f82c
refactor: 애니메이션 로직 정리
WaiNaat e1ee3c1
refactor: 애니메이션 계산 로직 분리
WaiNaat 6ef34e2
Merge branch 'develop' into feature/425-awesome_nav_bar
WaiNaat e66cdb0
fix: typo
WaiNaat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const Wrapper = styled.div` | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
|
||
width: 64px; | ||
height: 100%; | ||
`; | ||
|
||
export const Center = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: space-evenly; | ||
|
||
width: 100%; | ||
height: 48px; | ||
|
||
& > * { | ||
transition: all 0.3s ease-out; | ||
} | ||
`; | ||
|
||
export const Text = styled.p<{ $isActive?: boolean }>` | ||
font-size: 1rem; | ||
font-weight: 700; | ||
line-height: 1.5rem; | ||
color: ${({ $isActive, theme: { color } }) => | ||
$isActive ? color.fontPrimaryForBackground : color.subLight}; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import SvgStroke, { ICONS } from 'components/@common/SvgIcons/SvgStroke'; | ||
import { Wrapper, Center, Text } from './NavItem.style'; | ||
import theme from 'style/theme.style'; | ||
|
||
interface NavItemProps { | ||
isActive: boolean; | ||
iconId: typeof ICONS[number]; | ||
label: string; | ||
} | ||
|
||
const NavItem = (props: NavItemProps) => { | ||
const { isActive, iconId, label } = props; | ||
const iconColor = isActive ? theme.color.fontPrimaryForBackground : theme.color.subLight; | ||
|
||
return ( | ||
<Wrapper> | ||
<Center> | ||
<SvgStroke color={iconColor} size={24} icon={iconId} /> | ||
<Text $isActive={isActive}>{label}</Text> | ||
</Center> | ||
</Wrapper> | ||
); | ||
}; | ||
|
||
export default NavItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useEffect, useRef } from 'react'; | ||
|
||
const useChildrenLeftPositions = <T extends HTMLElement>(domRef: React.RefObject<T>) => { | ||
const childrenPositions = useRef<number[]>([]); | ||
|
||
useEffect(() => { | ||
const resizeObserver = new ResizeObserver(([entry]) => { | ||
childrenPositions.current = Array.from(entry.target.children).map( | ||
(child) => child.getBoundingClientRect().left | ||
); | ||
}); | ||
|
||
if (domRef.current) resizeObserver.observe(domRef.current); | ||
return () => resizeObserver.disconnect(); | ||
}, [domRef]); | ||
|
||
return childrenPositions.current; | ||
}; | ||
|
||
export default useChildrenLeftPositions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,14 @@ import { useCallback, useMemo } from 'react'; | |
import createObserver from 'utils/createObserver'; | ||
|
||
const useIntersectionRef = (onIntersecting: () => void) => { | ||
const observer = useMemo(() => createObserver(onIntersecting), []); | ||
const observer = useMemo(() => createObserver(onIntersecting), [onIntersecting]); | ||
|
||
const intersectionRef = useCallback(<T extends Element>(instance: T | null) => { | ||
if (instance) observer.observe(instance); | ||
}, []); | ||
const intersectionRef = useCallback( | ||
<T extends Element>(instance: T | null) => { | ||
if (instance) observer.observe(instance); | ||
}, | ||
[observer] | ||
Comment on lines
+7
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 크~ 멋있ㅅ습니다 |
||
); | ||
|
||
return intersectionRef; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { useRef } from 'react'; | ||
import { useRecoilValue } from 'recoil'; | ||
import { isShowPageLoadingState } from 'store/atoms/@common'; | ||
import { URL_PATH } from 'constants/index'; | ||
import useChildrenLeftPositions from './useChildrenLeftPositions'; | ||
|
||
const getRoofPosition = (pathname: string) => { | ||
switch (pathname) { | ||
case URL_PATH.main: | ||
return 1; | ||
case URL_PATH.garden: | ||
return 2; | ||
case URL_PATH.reminder: | ||
return 3; | ||
case URL_PATH.petList: | ||
return 4; | ||
case URL_PATH.myPage: | ||
return 5; | ||
default: | ||
return null; | ||
} | ||
}; | ||
|
||
const getAnimationOffset = (prevPathname: string, currentPathname: string, positions: number[]) => { | ||
const prevRoofPosition = getRoofPosition(prevPathname); | ||
const roofPosition = getRoofPosition(currentPathname); | ||
|
||
const transitionOffset = | ||
roofPosition && prevRoofPosition | ||
? positions[prevRoofPosition - 1] - positions[roofPosition - 1] | ||
: 0; | ||
|
||
return transitionOffset !== 0 ? transitionOffset + Math.random() : 0; | ||
}; | ||
|
||
const useNavbarRoofAnimation = (prevPathname: string, currentPathname: string) => { | ||
const navbarRef = useRef<HTMLElement>(null); | ||
const isPageLoading = useRecoilValue(isShowPageLoadingState); | ||
|
||
const navItemPositions = useChildrenLeftPositions(navbarRef); | ||
|
||
const roofPosition = getRoofPosition(isPageLoading ? prevPathname : currentPathname); | ||
const transitionOffset = !isPageLoading | ||
? getAnimationOffset(prevPathname, currentPathname, navItemPositions) | ||
: 0; | ||
|
||
return { navbarRef, roofPosition, transitionOffset }; | ||
}; | ||
|
||
export default useNavbarRoofAnimation; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
R
전체적으로 Roof관련된 로직을 훅으로 분리하면 좀 더 깔끔할 것 같아요!
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.
R
아까 말한 프레임 드랍도 같이 해결하면 좋을 것 같아요!
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.
근데 이걸 훅으로 분리한다고 관심사 분리가 잘 될지는 모르겠네요..
roof position 자체가 navbar 내용물 순서에 종속되어 있는데 이 내용들이 jsx에 하드코딩되어 있기 때문에 어디를 분리하는 게 맞는지 잘 모르겠어요
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.
requestAnimationFrame도 찾아보니 화면 주사율에 따라서 호출 횟수가 달라서 이동 시간을 모든 모니터에서 동일하게 맞출 수 있는 방법이 있을까요?