Skip to content

Commit 2b58486

Browse files
committed
feat: 상세부분 스크롤에 대한 이미지처리
- 아래의 상세 부분을 아래로 스크롤할때, 이미지는 작아지고 공유버튼의 아이콘만 보이도록 반영
1 parent 7e25892 commit 2b58486

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

apps/web/src/pages/MemeDetailPage/MemeDetailPage.styles.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import styled from '@emotion/styled';
2+
import { motion } from 'motion/react';
23

34
const Container = styled.div`
45
width: 100%;
@@ -8,16 +9,16 @@ const Container = styled.div`
89
&::-webkit-scrollbar {
910
display: none;
1011
}
12+
scroll-behavior: smooth;
13+
-webkit-overflow-scrolling: touch;
1114
`;
1215

13-
const ImageContainer = styled.div<{ scrollProgress: number }>`
16+
const ImageContainer = styled(motion.div)`
1417
width: 100%;
1518
position: sticky;
1619
top: 0;
1720
z-index: 10;
18-
height: ${({ scrollProgress }) => Math.max(200, 400 - scrollProgress)}px;
1921
padding: 14px;
20-
transition: height 0.1s linear;
2122
background-color: ${({ theme }) => theme.palette.gray['gray-10']};
2223
`;
2324

@@ -28,7 +29,7 @@ const Image = styled.img`
2829
border-radius: 12px;
2930
`;
3031

31-
const ShareButton = styled.button<{ scrollProgress: number }>`
32+
const ShareButton = styled(motion.button)`
3233
position: absolute;
3334
display: flex;
3435
align-items: center;
@@ -38,22 +39,16 @@ const ShareButton = styled.button<{ scrollProgress: number }>`
3839
transform: translateX(-50%);
3940
bottom: 26px;
4041
border: 1px solid ${({ theme }) => theme.palette.common.white};
41-
padding: ${({ scrollProgress }) =>
42-
scrollProgress > 50 ? '10px' : '10px 16px'};
4342
border-radius: 10px;
4443
cursor: pointer;
4544
color: ${({ theme }) => theme.palette.common.white};
46-
transition: all 0.1s linear;
4745
`;
4846

49-
const ShareButtonText = styled.span<{ scrollProgress: number }>`
47+
const ShareButtonText = styled(motion.span)`
5048
${({ theme }) => theme.typography.body.body1};
5149
color: ${({ theme }) => theme.palette.common.white};
52-
opacity: ${({ scrollProgress }) => Math.max(0, 1 - scrollProgress / 50)};
53-
max-width: ${({ scrollProgress }) => (scrollProgress > 50 ? '0' : '100px')};
5450
overflow: hidden;
5551
white-space: nowrap;
56-
transition: all 0.1s linear;
5752
`;
5853

5954
const ContentContainer = styled.div`

apps/web/src/pages/MemeDetailPage/index.tsx

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { nativeBridge } from '@/utils/bridge';
44
import * as S from './MemeDetailPage.styles';
55
import { useTheme } from '@emotion/react';
66
import { useRef } from 'react';
7-
import { useEffect, useState } from 'react';
7+
import { useScroll, useTransform, useSpring } from 'motion/react';
88

99
const DUMMY_DATA = {
1010
resultType: 'SUCCESS',
@@ -25,21 +25,27 @@ const DUMMY_DATA = {
2525

2626
const 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

Comments
 (0)