@@ -4,7 +4,7 @@ import { nativeBridge } from '@/utils/bridge';
44import * as S from './MemeDetailPage.styles' ;
55import { useTheme } from '@emotion/react' ;
66import { useRef } from 'react' ;
7- import { useEffect , useState } from 'react' ;
7+ import { useScroll , useTransform , useSpring } from 'motion/ react' ;
88
99const DUMMY_DATA = {
1010 resultType : 'SUCCESS' ,
@@ -25,21 +25,27 @@ const DUMMY_DATA = {
2525
2626const MemeDetailPage = ( ) => {
2727 const theme = useTheme ( ) ;
28- const [ scrollProgress , setScrollProgress ] = useState ( 0 ) ;
2928 const containerRef = useRef < HTMLDivElement > ( null ) ;
29+ const { scrollY } = useScroll ( { container : containerRef } ) ;
3030
31- useEffect ( ( ) => {
32- const container = containerRef . current ;
33- if ( ! container ) return ;
31+ const height = useTransform ( scrollY , [ 0 , 200 ] , [ 400 , 200 ] ) ;
32+ const smoothHeight = useSpring ( height , {
33+ stiffness : 200 ,
34+ damping : 20 ,
35+ mass : 0.5 ,
36+ } ) ;
3437
35- const handleScroll = ( ) => {
36- const scrollPosition = container . scrollTop ;
37- setScrollProgress ( Math . min ( 200 , scrollPosition ) ) ;
38- } ;
38+ const textWidth = useTransform ( scrollY , [ 0 , 50 ] , [ 100 , 0 ] ) ;
39+ const smoothTextWidth = useSpring ( textWidth , {
40+ stiffness : 300 ,
41+ damping : 30 ,
42+ } ) ;
3943
40- container . addEventListener ( 'scroll' , handleScroll ) ;
41- return ( ) => container . removeEventListener ( 'scroll' , handleScroll ) ;
42- } , [ ] ) ;
44+ const padding = useTransform ( scrollY , [ 0 , 50 ] , [ 16 , 10 ] ) ;
45+ const smoothPadding = useSpring ( padding , {
46+ stiffness : 300 ,
47+ damping : 30 ,
48+ } ) ;
4349
4450 return (
4551 < Layout
@@ -50,13 +56,13 @@ const MemeDetailPage = () => {
5056 } }
5157 >
5258 < S . Container ref = { containerRef } >
53- < S . ImageContainer scrollProgress = { scrollProgress } >
59+ < S . ImageContainer style = { { height : smoothHeight } } >
5460 < S . Image
5561 src = { DUMMY_DATA . success . image }
5662 alt = { DUMMY_DATA . success . title }
5763 />
5864 < S . ShareButton
59- scrollProgress = { scrollProgress }
65+ style = { { padding : smoothPadding } }
6066 onClick = { ( ) => {
6167 nativeBridge . shareMeme ( {
6268 title : DUMMY_DATA . success . title ,
@@ -65,7 +71,7 @@ const MemeDetailPage = () => {
6571 } }
6672 >
6773 < ShareIcon width = { 24 } height = { 24 } />
68- < S . ShareButtonText scrollProgress = { scrollProgress } >
74+ < S . ShareButtonText style = { { maxWidth : smoothTextWidth } } >
6975 공유하기
7076 </ S . ShareButtonText >
7177 </ S . ShareButton >
0 commit comments