Skip to content

Commit

Permalink
(#82) ๐Ÿš€ feat: ๋งˆ์šฐ์Šค ํœ  ์ด๋ฒคํŠธ ์ถ”๊ฐ€ํ•˜์—ฌ ์Šคํฌ๋กค๋ฐ”๊ฐ€ ์•ˆ ์ƒ๊ธฐ๋Š” ๊ฒฝ์šฐ์—๋„ ์Šคํฌ๋กค ์ด๋ฒคํŠธ๊ฐ€ ์ž‘๋™ํ•˜๋„๋ก ์ปค์Šคํ…€ ์Šคํฌ๋กค โ€ฆ
Browse files Browse the repository at this point in the history
โ€ฆํ›… ์ˆ˜์ •
  • Loading branch information
inaemon committed Nov 29, 2024
1 parent 9d1f576 commit 4c9bb28
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 63 deletions.
66 changes: 12 additions & 54 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 24 additions & 3 deletions src/hooks/useRefScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import { useState, useEffect, useRef } from "react";
// div์— overflow-auto๊ฐ€ css๋กœ ์„ค์ •๋œ ๊ฒฝ์šฐ window.scrollY๋กœ๋Š” ๊ฐ์ง€๊ฐ€ ๋ถˆ๊ฐ€ํ•˜์—ฌ
// ํ•ด๋‹น div์˜ ์ฐธ์กฐ(ref)๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ๊ทธ ์ฐธ์กฐ์— ์ด๋ฒคํŠธ๋ฅผ ๋ฐ”์ธ๋”ฉํ•ด์•ผ ํ•œ๋‹ค
const useRefScroll = <T extends HTMLElement>() => {
const [scrollDirection, setScrollDirection] = useState<"up" | "down" | null>(
null
);
const [scrollDirection, setScrollDirection] = useState<"up" | "down" | null> (null);
const [scrollPosition, setScrollPosition] = useState(0);
const containerRef = useRef<T | null>(null);

useEffect(() => {
let prevScrollPos = 0;
let startY: number | null = null;

// ๋ฐ์Šคํฌํƒ‘ ์ „์šฉ
// overflow-auto๊ฐ€ ์„ค์ •๋œ div์—์„œ height๊ฐ€ ์งง์•„์„œ scroll bar๊ฐ€ ์ƒ๊ธฐ๋Š” ๊ฒฝ์šฐ์— ์Šคํฌ๋กค์„ ๊ฐ์ง€ํ•˜๋Š” ์ด๋ฒคํŠธ
const handleScroll = () => {
const container = containerRef.current;
if (!container) return;
Expand All @@ -30,6 +30,26 @@ const useRefScroll = <T extends HTMLElement>() => {
prevScrollPos = currentScrollPos;
};

// ๋ฐ์Šคํฌํƒ‘ ์ „์šฉ
// height๊ฐ€ ์ด๋ฏธ ๊ธธ์•„์„œ scroll bar๊ฐ€ ์•ˆ ์ƒ๊ธฐ๋Š” ๊ฒฝ์šฐ์— ๋งˆ์šฐ์Šค ํœ ๋กœ ์Šคํฌ๋กค์„ ๊ฐ์ง€ํ•˜๋Š” ์ด๋ฒคํŠธ
const handleWheel = (e: WheelEvent) => {
const container = containerRef.current;
if (!container) return;

// ๋งˆ์šฐ์Šค ํœ  ์Šคํฌ๋กค ๋ฐฉํ–ฅ ๊ฐ์ง€
if (e.deltaY > 0) {
setScrollDirection("down");
} else if (e.deltaY < 0) {
setScrollDirection("up");
}

// wheel ์ด๋ฒคํŠธ๋Š” scrollTop ๊ฐ’์„ ์ง์ ‘ ๋ณ€๊ฒฝํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ, ์ด๋ฅผ ์—…๋ฐ์ดํŠธ
setScrollPosition(container.scrollTop);
};


// ๋ชจ๋ฐ”์ผ ๊ธฐ๊ธฐ ์ „์šฉ
// ํ„ฐ์น˜๋ฅผ ๊ฐ์ง€ํ•˜๋Š” ์ด๋ฒคํŠธ
const handleTouchStart = (e: TouchEvent) => {
startY = e.touches[0].clientY;
};
Expand All @@ -53,6 +73,7 @@ const useRefScroll = <T extends HTMLElement>() => {
const container = containerRef.current;
if (container) {
container.addEventListener("scroll", handleScroll);
container.addEventListener("wheel", handleWheel); // wheel ์ด๋ฒคํŠธ ์ถ”๊ฐ€
container.addEventListener("touchstart", handleTouchStart);
container.addEventListener("touchmove", handleTouchMove);
}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Home/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const HomePage = () => {


return (
<div>
<>
{/* ์ดˆ๊ธฐ ํŽ˜์ด์ง€ */}
{currentPage === 'init' && <InitPage/>}

Expand All @@ -52,7 +52,7 @@ const HomePage = () => {

{/* ๋ฉ”์ธ ํŽ˜์ด์ง€ */}
{currentPage === 'main' && <Main />}
</div>
</>
);
};

Expand Down
12 changes: 9 additions & 3 deletions src/pages/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,21 @@ const Main = () => {
return (
<div
ref={containerRef} // ์Šคํฌ๋กค์„ ๊ฐ์ง€ํ•  ํŠน์ • div์— Ref๋ฅผ ๋ฐ”์ธ๋”ฉ
className="flex flex-col w-full min-h-screen overflow-auto scrollbar-hide pt-14">
className="flex flex-col w-full overflow-auto scrollbar-hide pt-14"
/*
style={{
height: '1000px', // ๋†’์ด๋ฅผ ์„ค์ •ํ•˜์—ฌ ์Šคํฌ๋กค์„ ๋ฐœ์ƒ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋„๋ก
overflowY: 'scroll', // ์ˆ˜์ง ์Šคํฌ๋กค ํ™œ์„ฑํ™”
}}
*/
>
{renderScrollState()}
{/* ์ฝ”์น˜๋งˆํฌ
{showCoachMark && <CoachMark onClose={() => setShowCoachMark(false)} />}
*/}
{/* ์ฝ”์น˜๋งˆํฌ๊ฐ€ ๋น„ํ™œ์„ฑํ™”๋œ ๊ฒฝ์šฐ์—๋งŒ ๋ฉ”์ธ ์ฝ˜ํ…์ธ  ๋ Œ๋”๋ง
{!showCoachMark && (
*/}
<>
<Header />
<div className="flex-1 px-4 pb-24 bg-grayscale-5">
<p className="text-xl font-bold text-grayscale-90 pt-5 text-left w-full">
Expand Down Expand Up @@ -168,7 +175,6 @@ const Main = () => {

{/* ์ค€๋น„ ์ค‘์ธ ๊ตฌ์žฅ ์„ ํƒ ์‹œ ๋‚˜์˜ค๋Š” ํŒ์—… */}
<ReadyStadiumDialog isOpen={isPopupOpen} onClose={closePopup} />
</>
{/*s
)}
*/}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const MyApp: React.FC<AppProps> = ({ Component, pageProps: { session, ...pagePro
</Head>

{/*<SessionProvider session={session}>*/}
<div className="flex flex-col h-screen max-w-[500px] mx-auto ">
<div className="flex flex-col h-screen max-w-[500px] mx-auto overflow-hidden">
{renderComponent()}
</div>
{/*</SessionProvider> */}
Expand Down

0 comments on commit 4c9bb28

Please sign in to comment.