Skip to content

Commit 5eb004f

Browse files
committed
Fix: 모바일화면에서 깜빡임 제거
1 parent 6d7eb21 commit 5eb004f

File tree

4 files changed

+42
-26
lines changed

4 files changed

+42
-26
lines changed

app/(blog)/posts/[...slug]/post-content.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Post } from "@/lib/posts";
88
import Link from "next/link";
99
import { motion } from "framer-motion";
1010
import { ArrowLeft, ArrowRight } from "lucide-react";
11+
import { useIsMobile } from "@/hooks/use-mobile";
1112

1213
interface PostContentProps {
1314
content: string;
@@ -28,6 +29,11 @@ export default function PostContent({
2829
prevPost,
2930
nextPost,
3031
}: PostContentProps) {
32+
const isMobile = useIsMobile();
33+
34+
// 모바일에서 애니메이션 비활성화
35+
const disableAnimation = isMobile;
36+
3137
return (
3238
<>
3339
<div className="flex flex-col lg:flex-row gap-6">
@@ -40,6 +46,7 @@ export default function PostContent({
4046
published={published}
4147
modified={modified}
4248
tags={tags}
49+
disableAnimation={disableAnimation}
4350
/>
4451
</div>
4552

@@ -49,8 +56,8 @@ export default function PostContent({
4956
{prevPost ? (
5057
<motion.div
5158
className="w-full sm:w-auto"
52-
whileHover={{ x: -3 }}
53-
transition={{ type: "spring", stiffness: 400, damping: 15 }}
59+
whileHover={disableAnimation ? {} : { x: -3 }}
60+
transition={{ type: "spring", stiffness: 400, damping: 15, duration: 0.1 }}
5461
>
5562
<Link
5663
href={`/posts/${prevPost.urlPath}`}
@@ -80,8 +87,8 @@ export default function PostContent({
8087
{nextPost ? (
8188
<motion.div
8289
className="w-full sm:w-auto text-right"
83-
whileHover={{ x: 3 }}
84-
transition={{ type: "spring", stiffness: 400, damping: 15 }}
90+
whileHover={disableAnimation ? {} : { x: 3 }}
91+
transition={{ type: "spring", stiffness: 400, damping: 15, duration: 0.1 }}
8592
>
8693
<Link
8794
href={`/posts/${nextPost.urlPath}`}

components/left-sidebar.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Button } from "@/components/ui/button";
55
import { Menu } from "lucide-react";
66
import { TreeView } from "@/components/tree-view";
77
import { useState } from "react";
8+
import { useIsMobile } from "@/hooks/use-mobile";
89
import { DialogTitle, DialogDescription } from "@radix-ui/react-dialog";
910
import { usePosts } from "@/contexts/posts-context";
1011
import { buildFolderStructure } from "@/lib/utils";
@@ -21,6 +22,7 @@ export default function LeftSidebar({ className }: LeftSidebarProps) {
2122
const [open, setOpen] = useState(false);
2223
const { posts } = usePosts();
2324
const pathname = usePathname();
25+
const isMobile = useIsMobile();
2426
const folderStructure = buildFolderStructure(posts);
2527

2628
// URL이 변경될 때마다 컴포넌트를 강제로 리렌더링하기 위한 key 생성
@@ -56,21 +58,21 @@ export default function LeftSidebar({ className }: LeftSidebarProps) {
5658
{/* 데스크톱 버전 */}
5759
<motion.aside
5860
key={sidebarKey}
59-
className={cn("hidden xl:block", className)}
60-
initial={{ opacity: 0, x: -20 }}
61+
className={cn("hidden xl:block motion-gpu", className)}
62+
initial={false} // 깜빡임 방지
6163
animate={{ opacity: 1, x: 0 }}
6264
transition={{
63-
duration: 0.15,
65+
duration: isMobile ? 0.1 : 0.15,
6466
ease: "easeOut",
65-
delay: 0.05
67+
delay: 0
6668
}}
6769
>
6870
<ScrollArea className="h-full">
6971
<SidebarSection title="카테고리">
7072
<motion.div
71-
initial={{ opacity: 0 }}
73+
initial={false}
7274
animate={{ opacity: 1 }}
73-
transition={{ delay: 0.1, duration: 0.1 }}
75+
transition={{ duration: isMobile ? 0.05 : 0.1 }}
7476
>
7577
<TreeView key={`desktop-tree-${pathname}`} data={folderStructure} />
7678
</motion.div>

components/markdown-renderer.tsx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import { Element } from "hast";
88
import CodeBlock from "./code-block";
99
import { motion } from "framer-motion";
1010
import remarkCallout from "@r4ai/remark-callout";
11+
import { useIsMobile } from "@/hooks/use-mobile";
1112

1213
export interface MarkdownRendererProps {
1314
content: string;
1415
publish?: string;
1516
tags?: string[];
1617
published?: string;
1718
modified?: string;
19+
disableAnimation?: boolean; // 애니메이션 비활성화 옵션 추가
1820
}
1921

2022
interface LinkMap {
@@ -37,7 +39,11 @@ export default function MarkdownRenderer({
3739
tags,
3840
published,
3941
modified,
42+
disableAnimation = false,
4043
}: MarkdownRendererProps) {
44+
// 기본적으로 모바일에서는 애니메이션 비활성화
45+
const isMobile = useIsMobile();
46+
const shouldDisableAnimation = disableAnimation || isMobile;
4147
const [linkMap, setLinkMap] = useState<LinkMap>({});
4248
const [isMapLoaded, setIsMapLoaded] = useState(false);
4349
useEffect(() => {
@@ -291,10 +297,10 @@ export default function MarkdownRenderer({
291297
},
292298
img: ({ src, alt }: { src?: string; alt?: string }) => (
293299
<motion.div
294-
className="spacing-section relative group"
295-
initial={{ opacity: 0, scale: 0.95 }}
300+
className="spacing-section relative group motion-gpu"
301+
initial={shouldDisableAnimation ? false : { opacity: 0, scale: 0.95 }}
296302
animate={{ opacity: 1, scale: 1 }}
297-
transition={{ duration: 0.2 }}
303+
transition={{ duration: shouldDisableAnimation ? 0 : 0.2 }}
298304
>
299305
<div className="flex flex-col w-full items-center justify-center">
300306
<div
@@ -396,10 +402,10 @@ export default function MarkdownRenderer({
396402
blockquote: ({ children }: { children?: React.ReactNode }) => (
397403
<motion.blockquote
398404
className="spacing-paragraph border-l-4 border-primary pl-4 sm:pl-5 md:pl-6 py-2 sm:py-3
399-
bg-primary/5 rounded-r-lg shadow-sm"
400-
initial={{ opacity: 0, x: -5 }}
405+
bg-primary/5 rounded-r-lg shadow-sm motion-gpu"
406+
initial={shouldDisableAnimation ? false : { opacity: 0, x: -5 }}
401407
animate={{ opacity: 1, x: 0 }}
402-
transition={{ duration: 0.15 }}
408+
transition={{ duration: shouldDisableAnimation ? 0 : 0.15 }}
403409
>
404410
<div className="text-foreground/80 italic font-medium">{children}</div>
405411
</motion.blockquote>
@@ -419,10 +425,10 @@ export default function MarkdownRenderer({
419425
),
420426
table: ({ children }: { children?: React.ReactNode }) => (
421427
<motion.div
422-
className="spacing-section overflow-x-auto rounded-md sm:rounded-lg border border-primary/10 shadow-sm"
423-
initial={{ opacity: 0 }}
428+
className="spacing-section overflow-x-auto rounded-md sm:rounded-lg border border-primary/10 shadow-sm motion-gpu"
429+
initial={shouldDisableAnimation ? false : { opacity: 0 }}
424430
animate={{ opacity: 1 }}
425-
transition={{ duration: 0.15 }}
431+
transition={{ duration: shouldDisableAnimation ? 0 : 0.15 }}
426432
>
427433
<table className="w-full border-collapse text-hierarchy-body">
428434
{children}
@@ -446,10 +452,10 @@ export default function MarkdownRenderer({
446452
),
447453
hr: () => (
448454
<motion.hr
449-
className="spacing-section border-none h-px bg-gradient-to-r from-transparent via-primary/30 to-transparent"
450-
initial={{ width: 0 }}
455+
className="spacing-section border-none h-px bg-gradient-to-r from-transparent via-primary/30 to-transparent motion-gpu"
456+
initial={shouldDisableAnimation ? false : { width: 0 }}
451457
animate={{ width: "100%" }}
452-
transition={{ duration: 0.2 }}
458+
transition={{ duration: shouldDisableAnimation ? 0 : 0.2 }}
453459
/>
454460
),
455461
input: ({ checked }: { checked?: boolean }) => (

components/right-sidebar.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ interface RightSidebarProps {
1717

1818
const RightSidebar = ({ className }: RightSidebarProps) => {
1919
const pathname = usePathname();
20+
const isMobile = useIsMobile();
2021

2122
// 포스트 페이지인지 확인 (/posts/로 시작하는 경로)
2223
const isPostPage = pathname.startsWith("/posts/");
@@ -27,13 +28,13 @@ const RightSidebar = ({ className }: RightSidebarProps) => {
2728
return (
2829
<motion.aside
2930
key={sidebarKey}
30-
className={cn("hidden xl:block", className)}
31-
initial={{ opacity: 0, x: 20 }}
31+
className={cn("hidden xl:block motion-gpu", className)}
32+
initial={false} // 모바일에서 깜빡임 방지를 위해 초기 애니메이션 비활성화
3233
animate={{ opacity: 1, x: 0 }}
3334
transition={{
34-
duration: 0.15,
35+
duration: isMobile ? 0.1 : 0.15,
3536
ease: "easeOut",
36-
delay: 0.05,
37+
delay: 0,
3738
}}
3839
>
3940
{isPostPage && (

0 commit comments

Comments
 (0)