Skip to content

Commit 0b0618d

Browse files
authored
Merge pull request #1 from Nexters/fix/meme-detail-scroll
fix: 밈 상세 페이지 스크롤 애니메이션 개선
2 parents 9a3e467 + ac68e66 commit 0b0618d

File tree

2 files changed

+19
-64
lines changed

2 files changed

+19
-64
lines changed

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

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,18 @@ import styled from '@emotion/styled';
22
import { motion } from 'motion/react';
33

44
const Container = styled.div`
5-
width: 100%;
6-
height: 100%;
75
overflow-y: auto;
8-
background-color: ${({ theme }) => theme.palette.gray['gray-10']};
96
&::-webkit-scrollbar {
107
display: none;
118
}
129
scroll-behavior: smooth;
1310
-webkit-overflow-scrolling: touch;
14-
position: relative;
1511
`;
1612

1713
const ImageContainer = styled(motion.div)`
18-
width: 100%;
1914
position: sticky;
2015
top: 0;
21-
z-index: 10;
22-
background-color: ${({ theme }) => theme.palette.gray['gray-10']};
23-
display: flex;
24-
flex-direction: column;
2516
padding: 14px;
26-
overflow: visible;
27-
position: relative;
2817
`;
2918

3019
const Image = styled.img`
@@ -36,39 +25,27 @@ const Image = styled.img`
3625

3726
const ShareButton = styled(motion.button)`
3827
position: absolute;
39-
display: inline-flex;
28+
display: flex;
4029
align-items: center;
41-
justify-content: center;
42-
gap: 8px;
30+
gap: 4px;
4331
background-color: rgba(0, 0, 0, 0.5);
4432
left: 50%;
4533
transform: translateX(-50%);
4634
bottom: 26px;
4735
border: 1px solid ${({ theme }) => theme.palette.common.white};
4836
border-radius: 10px;
49-
height: 44px;
50-
min-width: 44px;
51-
padding: 0 12px;
5237
cursor: pointer;
5338
color: ${({ theme }) => theme.palette.common.white};
54-
transition: all 0.2s ease;
55-
z-index: 20;
56-
white-space: nowrap;
39+
padding: 10px 12px;
5740
`;
5841

5942
const ShareButtonText = styled(motion.span)`
6043
${({ theme }) => theme.typography.body.body1};
6144
color: ${({ theme }) => theme.palette.common.white};
62-
display: block;
6345
`;
6446

6547
const ContentContainer = styled.div`
66-
padding: 0 14px 20px;
67-
background-color: ${({ theme }) => theme.palette.gray['gray-10']};
68-
margin-top: -20px;
69-
position: relative;
70-
z-index: 20;
71-
border-radius: 20px 20px 0 0;
48+
padding: 20px 14px;
7249
`;
7350

7451
const YearBadge = styled.div`
@@ -107,7 +84,7 @@ const SectionTitle = styled.h2`
10784
align-items: center;
10885
gap: 4px;
10986
width: max-content;
110-
padding: 4px 10px;
87+
padding: 6px 10px;
11188
border-radius: 6px;
11289
`;
11390

@@ -130,4 +107,4 @@ export {
130107
HashTags,
131108
SectionTitle,
132109
SectionText,
133-
};
110+
};

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

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ShareIcon, SymbolThreeIcon, SymbolTwoIcon } from '@/assets/icons';
33
import { nativeBridge } from '@/utils/bridge';
44
import * as S from './MemeDetailPage.styles';
55
import { useTheme } from '@emotion/react';
6-
import { useRef } from 'react';
6+
import { useRef, useState, useEffect } from 'react';
77
import { useScroll, useTransform, useSpring } from 'motion/react';
88

99
const DUMMY_DATA = {
@@ -28,31 +28,20 @@ const MemeDetailPage = () => {
2828
const containerRef = useRef<HTMLDivElement>(null);
2929
const { scrollY } = useScroll({ container: containerRef });
3030

31-
const height = useTransform(scrollY, [0, 200], [400, 250]);
31+
const height = useTransform(scrollY, [0, 60], [400, 175]);
3232
const smoothHeight = useSpring(height, {
33-
stiffness: 100,
34-
damping: 20,
33+
stiffness: 300,
34+
damping: 50,
3535
});
3636

37-
// 공유하기 버튼 애니메이션
38-
const buttonWidth = useTransform(scrollY, [0, 50], [116, 44]);
39-
const textOpacity = useTransform(scrollY, [0, 30], [1, 0]);
40-
const textWidth = useTransform(scrollY, [0, 30], [68, 0]);
37+
const [isTextVisible, setIsTextVisible] = useState(true);
4138

42-
const smoothButtonWidth = useSpring(buttonWidth, {
43-
stiffness: 400,
44-
damping: 40,
45-
});
46-
47-
const smoothTextWidth = useSpring(textWidth, {
48-
stiffness: 400,
49-
damping: 40,
50-
});
51-
52-
const smoothTextOpacity = useSpring(textOpacity, {
53-
stiffness: 400,
54-
damping: 40,
55-
});
39+
useEffect(() => {
40+
const unsubscribe = scrollY.on('change', (latest) => {
41+
setIsTextVisible(latest < 1);
42+
});
43+
return () => unsubscribe();
44+
}, [scrollY]);
5645

5746
return (
5847
<Layout
@@ -67,9 +56,6 @@ const MemeDetailPage = () => {
6756
alt={DUMMY_DATA.success.title}
6857
/>
6958
<S.ShareButton
70-
style={{
71-
width: smoothButtonWidth,
72-
}}
7359
onClick={() => {
7460
nativeBridge.shareMeme({
7561
title: DUMMY_DATA.success.title,
@@ -78,15 +64,7 @@ const MemeDetailPage = () => {
7864
}}
7965
>
8066
<ShareIcon width={24} height={24} />
81-
<S.ShareButtonText
82-
style={{
83-
opacity: smoothTextOpacity,
84-
width: smoothTextWidth,
85-
overflow: 'hidden',
86-
}}
87-
>
88-
공유하기
89-
</S.ShareButtonText>
67+
{isTextVisible && <S.ShareButtonText>공유하기</S.ShareButtonText>}
9068
</S.ShareButton>
9169
</S.ImageContainer>
9270
<S.ContentContainer>
@@ -113,4 +91,4 @@ const MemeDetailPage = () => {
11391
);
11492
};
11593

116-
export default MemeDetailPage;
94+
export default MemeDetailPage;

0 commit comments

Comments
 (0)