Skip to content

Commit c8eda44

Browse files
authored
[UNI-117] fix : 길찾기 결과 바텀 시트 아래로 내릴 시 스크롤 끝까지 안되는 현상 해결 (#51)
1 parent 43a1aa2 commit c8eda44

File tree

2 files changed

+78
-39
lines changed

2 files changed

+78
-39
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// container/animatedSheetContainer.tsx
2+
3+
import React from "react";
4+
import { AnimatePresence, motion, MotionProps } from "framer-motion";
5+
6+
type AnimatedSheetContainerProps = {
7+
isVisible: boolean;
8+
height: number;
9+
children: React.ReactNode;
10+
className?: string;
11+
transition?: MotionProps["transition"];
12+
motionProps?: MotionProps;
13+
};
14+
15+
const AnimatedSheetContainer = ({
16+
isVisible,
17+
height,
18+
children,
19+
className = "",
20+
transition = { duration: 0.3, type: "tween" },
21+
motionProps = {},
22+
}: AnimatedSheetContainerProps) => {
23+
return (
24+
<AnimatePresence>
25+
{isVisible && (
26+
<motion.div
27+
className={className}
28+
style={{
29+
position: "absolute",
30+
left: 0,
31+
bottom: 0,
32+
width: "100%",
33+
}}
34+
initial={{ height: 0 }}
35+
animate={{ height }}
36+
exit={{ height: 0 }}
37+
transition={transition}
38+
{...motionProps}
39+
>
40+
{children}
41+
</motion.div>
42+
)}
43+
</AnimatePresence>
44+
);
45+
};
46+
47+
export default AnimatedSheetContainer;

uniro_frontend/src/pages/navigationResult.tsx

+31-39
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,38 @@
11
import React, { useCallback, useEffect, useState } from "react";
22
import { PanInfo, useDragControls } from "framer-motion";
3+
import { useSuspenseQuery } from "@tanstack/react-query";
4+
35
import Button from "../components/customButton";
46
import RouteList from "../components/navigation/route/routeList";
5-
6-
import { mockNavigationRoute } from "../data/mock/hanyangRoute";
7-
import { NavigationRoute } from "../data/types/route";
8-
import useScrollControl from "../hooks/useScrollControl";
9-
import AnimatedContainer from "../container/animatedContainer";
10-
import NavigationMap from "../component/NavgationMap";
117
import NavigationDescription from "../components/navigation/navigationDescription";
128
import BottomSheetHandle from "../components/navigation/bottomSheet/bottomSheetHandle";
13-
14-
import useLoading from "../hooks/useLoading";
15-
import { useSuspenseQuery } from "@tanstack/react-query";
16-
import { getMockTest } from "../utils/fetch/mockFetch";
9+
import NavigationMap from "../component/NavgationMap";
1710
import BackButton from "../components/map/backButton";
11+
import AnimatedContainer from "../container/animatedContainer";
12+
import { mockNavigationRoute } from "../data/mock/hanyangRoute";
13+
import { NavigationRoute } from "../data/types/route";
14+
import { getMockTest } from "../utils/fetch/mockFetch";
1815

16+
import useScrollControl from "../hooks/useScrollControl";
17+
import useLoading from "../hooks/useLoading";
1918
import useUniversityInfo from "../hooks/useUniversityInfo";
2019
import useRedirectUndefined from "../hooks/useRedirectUndefined";
21-
22-
23-
// 1. 돌아가면 위치 reset ✅
24-
// 2. 상세경로 scroll 끝까지 가능하게 하기 ❎
25-
// 3. 코드 리팩토링 하기
20+
import AnimatedSheetContainer from "../container/animatedSheetContainer";
2621

2722
const MAX_SHEET_HEIGHT = window.innerHeight * 0.7;
2823
const MIN_SHEET_HEIGHT = window.innerHeight * 0.35;
2924
const CLOSED_SHEET_HEIGHT = 0;
3025

3126
const INITIAL_TOP_BAR_HEIGHT = 143;
3227
const BOTTOM_SHEET_HANDLE_HEIGHT = 40;
33-
3428
const PADDING_FOR_MAP_BOUNDARY = 50;
3529

3630
const NavigationResultPage = () => {
3731
const [isDetailView, setIsDetailView] = useState(false);
38-
3932
const [sheetHeight, setSheetHeight] = useState(CLOSED_SHEET_HEIGHT);
4033
const [topBarHeight, setTopBarHeight] = useState(INITIAL_TOP_BAR_HEIGHT);
4134

42-
const [isLoading, show, hide] = useLoading();
35+
const [isLoading, showLoading, hideLoading] = useLoading();
4336
const [route, setRoute] = useState<NavigationRoute>(mockNavigationRoute);
4437

4538
useScrollControl();
@@ -62,48 +55,46 @@ const NavigationResultPage = () => {
6255
setTopBarHeight(PADDING_FOR_MAP_BOUNDARY);
6356
setIsDetailView(true);
6457
};
58+
6559
const hideDetailView = () => {
6660
setSheetHeight(CLOSED_SHEET_HEIGHT);
6761
setTopBarHeight(INITIAL_TOP_BAR_HEIGHT);
6862
setIsDetailView(false);
6963
};
7064

71-
const handleDrag = useCallback(
72-
(event: Event, info: PanInfo) => {
73-
setSheetHeight((prev) => {
74-
const newHeight = prev - info.delta.y;
75-
return Math.min(Math.max(newHeight, MIN_SHEET_HEIGHT), MAX_SHEET_HEIGHT);
76-
});
77-
},
78-
[setSheetHeight, MAX_SHEET_HEIGHT, MIN_SHEET_HEIGHT],
79-
);
65+
const handleDrag = useCallback((event: Event, info: PanInfo) => {
66+
setSheetHeight((prev) => {
67+
const newHeight = prev - info.delta.y;
68+
return Math.min(Math.max(newHeight, MIN_SHEET_HEIGHT), MAX_SHEET_HEIGHT);
69+
});
70+
}, []);
8071

8172
return (
8273
<div className="relative h-svh w-full max-w-[450px] mx-auto">
74+
{/* 지도 영역 */}
8375
<NavigationMap
8476
style={{ width: "100%", height: "100%" }}
8577
routes={route}
8678
topPadding={topBarHeight}
8779
bottomPadding={sheetHeight}
8880
/>
81+
8982
<AnimatedContainer
9083
isVisible={!isDetailView && !isLoading}
9184
positionDelta={286}
9285
className="absolute top-0 z-10 max-w-[450px] w-full min-h-[143px] bg-gray-100 flex flex-col items-center justify-center rounded-b-4xl shadow-lg"
9386
isTop={true}
9487
transition={{ type: "spring", damping: 20, duration: 0.3 }}
9588
>
96-
<NavigationDescription isDetailView={!isDetailView && !isLoading} />
89+
<NavigationDescription isDetailView={false} />
9790
</AnimatedContainer>
9891

9992
<AnimatedContainer
10093
isVisible={!isDetailView && !isLoading}
10194
className="absolute bottom-0 left-0 w-full mb-[30px] px-4"
10295
positionDelta={88}
10396
>
104-
<Button className="" onClick={showDetailView}>
105-
상세경로 보기
106-
</Button>
97+
<Button onClick={showDetailView}>상세경로 보기</Button>
10798
</AnimatedContainer>
10899

109100
<AnimatedContainer
@@ -115,38 +106,39 @@ const NavigationResultPage = () => {
115106
<BackButton onClick={hideDetailView} />
116107
</AnimatedContainer>
117108

118-
<AnimatedContainer
109+
<AnimatedSheetContainer
119110
isVisible={isDetailView && !isLoading}
120-
className="absolute bottom-0 w-full left-0 bg-white rounded-t-2xl shadow-xl overflow-auto"
121-
positionDelta={MAX_SHEET_HEIGHT}
122-
transition={{ type: "spring", damping: 20, duration: 0.3 }}
111+
height={sheetHeight}
112+
className="bg-white rounded-t-2xl shadow-xl"
113+
transition={{ type: "tween", duration: 0.3 }}
123114
motionProps={{
124115
drag: "y",
125116
dragControls,
126117
dragListener: false,
127118
dragConstraints: {
128119
top: 0,
129-
bottom: MIN_SHEET_HEIGHT,
120+
bottom: 0,
130121
},
131122
onDrag: handleDrag,
132123
onDragEnd: handleDrag,
133124
}}
134125
>
135126
<BottomSheetHandle dragControls={dragControls} />
127+
136128
<div
137129
className="w-full overflow-y-auto"
138130
style={{
139-
height: MAX_SHEET_HEIGHT - BOTTOM_SHEET_HANDLE_HEIGHT,
131+
height: sheetHeight - BOTTOM_SHEET_HANDLE_HEIGHT,
140132
}}
141133
>
142-
<NavigationDescription isDetailView={isDetailView && !isLoading} />
134+
<NavigationDescription isDetailView={true} />
143135
<RouteList
144136
routes={route.route}
145137
originBuilding={route.originBuilding}
146138
destinationBuilding={route.destinationBuilding}
147139
/>
148140
</div>
149-
</AnimatedContainer>
141+
</AnimatedSheetContainer>
150142
</div>
151143
);
152144
};

0 commit comments

Comments
 (0)