1
1
import React , { useCallback , useEffect , useState } from "react" ;
2
2
import { PanInfo , useDragControls } from "framer-motion" ;
3
+ import { useSuspenseQuery } from "@tanstack/react-query" ;
4
+
3
5
import Button from "../components/customButton" ;
4
6
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" ;
11
7
import NavigationDescription from "../components/navigation/navigationDescription" ;
12
8
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" ;
17
10
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" ;
18
15
16
+ import useScrollControl from "../hooks/useScrollControl" ;
17
+ import useLoading from "../hooks/useLoading" ;
19
18
import useUniversityInfo from "../hooks/useUniversityInfo" ;
20
19
import useRedirectUndefined from "../hooks/useRedirectUndefined" ;
21
-
22
-
23
- // 1. 돌아가면 위치 reset ✅
24
- // 2. 상세경로 scroll 끝까지 가능하게 하기 ❎
25
- // 3. 코드 리팩토링 하기
20
+ import AnimatedSheetContainer from "../container/animatedSheetContainer" ;
26
21
27
22
const MAX_SHEET_HEIGHT = window . innerHeight * 0.7 ;
28
23
const MIN_SHEET_HEIGHT = window . innerHeight * 0.35 ;
29
24
const CLOSED_SHEET_HEIGHT = 0 ;
30
25
31
26
const INITIAL_TOP_BAR_HEIGHT = 143 ;
32
27
const BOTTOM_SHEET_HANDLE_HEIGHT = 40 ;
33
-
34
28
const PADDING_FOR_MAP_BOUNDARY = 50 ;
35
29
36
30
const NavigationResultPage = ( ) => {
37
31
const [ isDetailView , setIsDetailView ] = useState ( false ) ;
38
-
39
32
const [ sheetHeight , setSheetHeight ] = useState ( CLOSED_SHEET_HEIGHT ) ;
40
33
const [ topBarHeight , setTopBarHeight ] = useState ( INITIAL_TOP_BAR_HEIGHT ) ;
41
34
42
- const [ isLoading , show , hide ] = useLoading ( ) ;
35
+ const [ isLoading , showLoading , hideLoading ] = useLoading ( ) ;
43
36
const [ route , setRoute ] = useState < NavigationRoute > ( mockNavigationRoute ) ;
44
37
45
38
useScrollControl ( ) ;
@@ -62,48 +55,46 @@ const NavigationResultPage = () => {
62
55
setTopBarHeight ( PADDING_FOR_MAP_BOUNDARY ) ;
63
56
setIsDetailView ( true ) ;
64
57
} ;
58
+
65
59
const hideDetailView = ( ) => {
66
60
setSheetHeight ( CLOSED_SHEET_HEIGHT ) ;
67
61
setTopBarHeight ( INITIAL_TOP_BAR_HEIGHT ) ;
68
62
setIsDetailView ( false ) ;
69
63
} ;
70
64
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
+ } , [ ] ) ;
80
71
81
72
return (
82
73
< div className = "relative h-svh w-full max-w-[450px] mx-auto" >
74
+ { /* 지도 영역 */ }
83
75
< NavigationMap
84
76
style = { { width : "100%" , height : "100%" } }
85
77
routes = { route }
86
78
topPadding = { topBarHeight }
87
79
bottomPadding = { sheetHeight }
88
80
/>
81
+
89
82
< AnimatedContainer
90
83
isVisible = { ! isDetailView && ! isLoading }
91
84
positionDelta = { 286 }
92
85
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"
93
86
isTop = { true }
94
87
transition = { { type : "spring" , damping : 20 , duration : 0.3 } }
95
88
>
96
- < NavigationDescription isDetailView = { ! isDetailView && ! isLoading } />
89
+ < NavigationDescription isDetailView = { false } />
97
90
</ AnimatedContainer >
98
91
99
92
< AnimatedContainer
100
93
isVisible = { ! isDetailView && ! isLoading }
101
94
className = "absolute bottom-0 left-0 w-full mb-[30px] px-4"
102
95
positionDelta = { 88 }
103
96
>
104
- < Button className = "" onClick = { showDetailView } >
105
- 상세경로 보기
106
- </ Button >
97
+ < Button onClick = { showDetailView } > 상세경로 보기</ Button >
107
98
</ AnimatedContainer >
108
99
109
100
< AnimatedContainer
@@ -115,38 +106,39 @@ const NavigationResultPage = () => {
115
106
< BackButton onClick = { hideDetailView } />
116
107
</ AnimatedContainer >
117
108
118
- < AnimatedContainer
109
+ < AnimatedSheetContainer
119
110
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 } }
123
114
motionProps = { {
124
115
drag : "y" ,
125
116
dragControls,
126
117
dragListener : false ,
127
118
dragConstraints : {
128
119
top : 0 ,
129
- bottom : MIN_SHEET_HEIGHT ,
120
+ bottom : 0 ,
130
121
} ,
131
122
onDrag : handleDrag ,
132
123
onDragEnd : handleDrag ,
133
124
} }
134
125
>
135
126
< BottomSheetHandle dragControls = { dragControls } />
127
+
136
128
< div
137
129
className = "w-full overflow-y-auto"
138
130
style = { {
139
- height : MAX_SHEET_HEIGHT - BOTTOM_SHEET_HANDLE_HEIGHT ,
131
+ height : sheetHeight - BOTTOM_SHEET_HANDLE_HEIGHT ,
140
132
} }
141
133
>
142
- < NavigationDescription isDetailView = { isDetailView && ! isLoading } />
134
+ < NavigationDescription isDetailView = { true } />
143
135
< RouteList
144
136
routes = { route . route }
145
137
originBuilding = { route . originBuilding }
146
138
destinationBuilding = { route . destinationBuilding }
147
139
/>
148
140
</ div >
149
- </ AnimatedContainer >
141
+ </ AnimatedSheetContainer >
150
142
</ div >
151
143
) ;
152
144
} ;
0 commit comments