@akanjs/next 0.0.51 → 0.0.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +41 -0
- package/package.json +1 -1
- package/bootCsr.tsx +0 -180
- package/createNextMiddleware.ts +0 -45
- package/createRobotPage.ts +0 -14
- package/createSitemapPage.ts +0 -6
- package/index.ts +0 -23
- package/lazy.ts +0 -9
- package/makePageProto.tsx +0 -117
- package/types.ts +0 -7
- package/useCamera.tsx +0 -94
- package/useCodepush.tsx +0 -98
- package/useContact.tsx +0 -45
- package/useCsrValues.ts +0 -613
- package/useDebounce.ts +0 -23
- package/useFetch.ts +0 -24
- package/useGeoLocation.tsx +0 -21
- package/useHistory.ts +0 -55
- package/useInterval.ts +0 -20
- package/useLocation.ts +0 -65
- package/usePurchase.tsx +0 -155
- package/usePushNoti.tsx +0 -39
- package/useThrottle.ts +0 -17
package/useContact.tsx
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { device } from "@akanjs/client";
|
|
3
|
-
import { Contacts, PermissionStatus } from "@capacitor-community/contacts";
|
|
4
|
-
import { useEffect, useState } from "react";
|
|
5
|
-
|
|
6
|
-
export const useContact = () => {
|
|
7
|
-
const [permissions, setPermissions] = useState<PermissionStatus>({ contacts: "prompt" });
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 최초로 킬 경우 권한은 prompt 상태이다.
|
|
11
|
-
* prompt 상태일 경우 권한을 요청한다.
|
|
12
|
-
* 권한이 denied 상태일 경우 설정으로 이동한다.
|
|
13
|
-
* 이후 state의 permission을 업데이트해야한다.
|
|
14
|
-
*
|
|
15
|
-
*/
|
|
16
|
-
const checkPermission = async () => {
|
|
17
|
-
try {
|
|
18
|
-
if (permissions.contacts === "prompt") {
|
|
19
|
-
const { contacts } = await Contacts.requestPermissions();
|
|
20
|
-
setPermissions((prev) => ({ ...prev, contacts }));
|
|
21
|
-
} else if (permissions.contacts === "denied") {
|
|
22
|
-
location.assign("app-settings:");
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
} catch (e) {
|
|
26
|
-
//
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const getContacts = async () => {
|
|
31
|
-
await checkPermission();
|
|
32
|
-
const { contacts } = await Contacts.getContacts({ projection: { name: true, phones: true } });
|
|
33
|
-
return contacts;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
void (async () => {
|
|
38
|
-
if (device.info.platform === "web") return;
|
|
39
|
-
const permissions = await Contacts.checkPermissions();
|
|
40
|
-
setPermissions(permissions);
|
|
41
|
-
})();
|
|
42
|
-
}, []);
|
|
43
|
-
|
|
44
|
-
return { permissions, getContacts, checkPermission };
|
|
45
|
-
};
|
package/useCsrValues.ts
DELETED
|
@@ -1,613 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {
|
|
3
|
-
type CsrContextType,
|
|
4
|
-
type CsrTransitionStyles,
|
|
5
|
-
defaultPageState,
|
|
6
|
-
device,
|
|
7
|
-
LocationState,
|
|
8
|
-
PathRoute,
|
|
9
|
-
type RouteGuide,
|
|
10
|
-
router,
|
|
11
|
-
type RouterInstance,
|
|
12
|
-
type RouteState,
|
|
13
|
-
type TransitionType,
|
|
14
|
-
type UseCsrTransition,
|
|
15
|
-
} from "@akanjs/client";
|
|
16
|
-
import { App } from "@capacitor/app";
|
|
17
|
-
import { useSpringValue } from "@react-spring/web";
|
|
18
|
-
import { useDrag } from "@use-gesture/react";
|
|
19
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
20
|
-
|
|
21
|
-
import { useHistory } from "./useHistory";
|
|
22
|
-
import { useLocation } from "./useLocation";
|
|
23
|
-
|
|
24
|
-
const useNoneTrans = ({ clientHeight, location, prevLocation }: RouteState): UseCsrTransition => {
|
|
25
|
-
const transDirection = "none";
|
|
26
|
-
const transUnit = useSpringValue(0, { config: { clamp: true } });
|
|
27
|
-
const transUnitRange = useMemo(() => [0, 0], []);
|
|
28
|
-
const transProgress = transUnit.to((unit) => 1);
|
|
29
|
-
const transPercent = transUnit.to((unit) => 100);
|
|
30
|
-
const pageState = location.pathRoute.pageState;
|
|
31
|
-
const prevPageState = prevLocation?.pathRoute.pageState ?? defaultPageState;
|
|
32
|
-
const csrTranstionStyles: CsrTransitionStyles = {
|
|
33
|
-
topSafeArea: {
|
|
34
|
-
containerStyle: {
|
|
35
|
-
height: pageState.topSafeArea,
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
bottomSafeArea: {
|
|
39
|
-
containerStyle: {
|
|
40
|
-
top: clientHeight - pageState.bottomSafeArea,
|
|
41
|
-
height: pageState.bottomSafeArea,
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
page: {
|
|
45
|
-
containerStyle: {},
|
|
46
|
-
contentStyle: {
|
|
47
|
-
paddingTop: pageState.topSafeArea + pageState.topInset,
|
|
48
|
-
paddingBottom: pageState.bottomInset + pageState.bottomSafeArea,
|
|
49
|
-
height: clientHeight,
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
prevPage: {
|
|
53
|
-
containerStyle: {
|
|
54
|
-
paddingTop: prevPageState.topSafeArea + prevPageState.topInset,
|
|
55
|
-
},
|
|
56
|
-
contentStyle: { opacity: 0 },
|
|
57
|
-
},
|
|
58
|
-
topInset: {
|
|
59
|
-
containerStyle: {
|
|
60
|
-
top: pageState.topSafeArea,
|
|
61
|
-
height: pageState.topInset,
|
|
62
|
-
},
|
|
63
|
-
contentStyle: { opacity: 1 },
|
|
64
|
-
prevContentStyle: { opacity: 0 },
|
|
65
|
-
},
|
|
66
|
-
topLeftAction: {
|
|
67
|
-
containerStyle: {
|
|
68
|
-
top: pageState.topSafeArea,
|
|
69
|
-
height: pageState.topInset,
|
|
70
|
-
},
|
|
71
|
-
contentStyle: { opacity: 1 },
|
|
72
|
-
prevContentStyle: { opacity: 0 },
|
|
73
|
-
},
|
|
74
|
-
bottomInset: {
|
|
75
|
-
containerStyle: {
|
|
76
|
-
height: pageState.bottomInset,
|
|
77
|
-
top: clientHeight - pageState.bottomInset - pageState.bottomSafeArea,
|
|
78
|
-
},
|
|
79
|
-
contentStyle: { opacity: 1 },
|
|
80
|
-
prevContentStyle: { opacity: 0 },
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const useCsrTransition: UseCsrTransition = {
|
|
85
|
-
...csrTranstionStyles,
|
|
86
|
-
pageBind: () => ({}),
|
|
87
|
-
pageClassName: "touch-pan-y",
|
|
88
|
-
transDirection,
|
|
89
|
-
transUnitRange,
|
|
90
|
-
transUnit,
|
|
91
|
-
transPercent,
|
|
92
|
-
transProgress,
|
|
93
|
-
};
|
|
94
|
-
return useCsrTransition;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const useFadeTrans = ({ clientHeight, location, prevLocation, onBack, history }: RouteState): UseCsrTransition => {
|
|
98
|
-
const transDirection = "none";
|
|
99
|
-
const transUnit = useSpringValue(1, { config: { clamp: true } });
|
|
100
|
-
const transUnitRange = useMemo(() => [0, 1], []);
|
|
101
|
-
const transProgress = transUnit.to((unit) => unit);
|
|
102
|
-
const transPercent = transUnit.to([0, 1], [0, 100], "clamp");
|
|
103
|
-
const pageState = location.pathRoute.pageState;
|
|
104
|
-
const prevPageState = prevLocation?.pathRoute.pageState ?? defaultPageState;
|
|
105
|
-
|
|
106
|
-
useEffect(() => {
|
|
107
|
-
onBack.current.fade = async () => {
|
|
108
|
-
await transUnit.start(transUnitRange[0]);
|
|
109
|
-
};
|
|
110
|
-
}, []);
|
|
111
|
-
useEffect(() => {
|
|
112
|
-
if (history.current.type === "forward") {
|
|
113
|
-
void transUnit.start(transUnitRange[0], { immediate: true });
|
|
114
|
-
void transUnit.start(transUnitRange[1], { config: { duration: 150 } });
|
|
115
|
-
} else {
|
|
116
|
-
void transUnit.start(transUnitRange[1], { immediate: true });
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
}, [location.pathname]);
|
|
120
|
-
|
|
121
|
-
const csrTranstionStyles: CsrTransitionStyles = {
|
|
122
|
-
topSafeArea: {
|
|
123
|
-
containerStyle: {
|
|
124
|
-
height: transProgress.to([0, 1], [prevPageState.topSafeArea, pageState.topSafeArea]),
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
bottomSafeArea: {
|
|
128
|
-
containerStyle: {
|
|
129
|
-
top: transProgress.to(
|
|
130
|
-
[0, 1],
|
|
131
|
-
[clientHeight - prevPageState.bottomSafeArea, clientHeight - pageState.bottomSafeArea]
|
|
132
|
-
),
|
|
133
|
-
height: transProgress.to([0, 1], [prevPageState.bottomSafeArea, pageState.bottomSafeArea]),
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
page: {
|
|
137
|
-
containerStyle: {},
|
|
138
|
-
contentStyle: {
|
|
139
|
-
paddingTop: pageState.topSafeArea + pageState.topInset,
|
|
140
|
-
paddingBottom: pageState.bottomInset + pageState.bottomSafeArea,
|
|
141
|
-
opacity: transUnit,
|
|
142
|
-
height: clientHeight,
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
prevPage: {
|
|
146
|
-
containerStyle: {
|
|
147
|
-
paddingTop: prevPageState.topSafeArea + prevPageState.topInset,
|
|
148
|
-
opacity: transProgress.to((progress) => 1 - progress),
|
|
149
|
-
},
|
|
150
|
-
contentStyle: {},
|
|
151
|
-
},
|
|
152
|
-
topInset: {
|
|
153
|
-
containerStyle: {
|
|
154
|
-
top: transProgress.to([0, 1], [prevPageState.topSafeArea, pageState.topSafeArea]),
|
|
155
|
-
height: transProgress.to([0, 1], [prevPageState.topInset, pageState.topInset]),
|
|
156
|
-
},
|
|
157
|
-
contentStyle: {
|
|
158
|
-
opacity: transProgress,
|
|
159
|
-
},
|
|
160
|
-
prevContentStyle: {
|
|
161
|
-
opacity: transProgress.to((progress) => 1 - progress),
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
topLeftAction: {
|
|
165
|
-
containerStyle: {
|
|
166
|
-
top: transProgress.to([0, 1], [prevPageState.topSafeArea, pageState.topSafeArea]),
|
|
167
|
-
height: transProgress.to([0, 1], [prevPageState.topInset, pageState.topInset]),
|
|
168
|
-
},
|
|
169
|
-
contentStyle: {
|
|
170
|
-
opacity: transProgress.to((progress) => progress),
|
|
171
|
-
},
|
|
172
|
-
prevContentStyle: {
|
|
173
|
-
opacity: transProgress.to((progress) => 1 - progress),
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
bottomInset: {
|
|
177
|
-
containerStyle: {
|
|
178
|
-
height: transProgress.to([0, 1], [prevPageState.bottomInset, pageState.bottomInset]),
|
|
179
|
-
top: transProgress.to(
|
|
180
|
-
[0, 1],
|
|
181
|
-
[
|
|
182
|
-
clientHeight - prevPageState.bottomInset - prevPageState.bottomSafeArea,
|
|
183
|
-
clientHeight - pageState.bottomInset - pageState.bottomSafeArea,
|
|
184
|
-
]
|
|
185
|
-
),
|
|
186
|
-
},
|
|
187
|
-
contentStyle: {
|
|
188
|
-
top: transProgress.to([0, 1], [0, -(pageState.bottomInset - prevPageState.bottomInset) * 2]),
|
|
189
|
-
opacity: transProgress.to((progress) => progress),
|
|
190
|
-
},
|
|
191
|
-
prevContentStyle: {
|
|
192
|
-
top: transProgress.to([0, 1], [0, -(pageState.bottomInset - prevPageState.bottomInset) * 2]),
|
|
193
|
-
opacity: transProgress.to((progress) => 1 - progress),
|
|
194
|
-
},
|
|
195
|
-
},
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
const useCsrTransition: UseCsrTransition = {
|
|
199
|
-
...csrTranstionStyles,
|
|
200
|
-
pageBind: () => ({}),
|
|
201
|
-
pageClassName: "",
|
|
202
|
-
transDirection,
|
|
203
|
-
transUnitRange,
|
|
204
|
-
transUnit,
|
|
205
|
-
transPercent,
|
|
206
|
-
transProgress,
|
|
207
|
-
};
|
|
208
|
-
return useCsrTransition;
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
const useStackTrans = ({
|
|
212
|
-
clientWidth,
|
|
213
|
-
clientHeight,
|
|
214
|
-
location,
|
|
215
|
-
prevLocation,
|
|
216
|
-
history,
|
|
217
|
-
onBack,
|
|
218
|
-
}: RouteState): UseCsrTransition => {
|
|
219
|
-
const transDirection = "horizontal";
|
|
220
|
-
const transUnit = useSpringValue(0, { config: { clamp: true } });
|
|
221
|
-
const transUnitRange = useMemo(() => [clientWidth, 0], []);
|
|
222
|
-
const transUnitReversed = transUnit.to((unit) => transUnitRange[0] - unit);
|
|
223
|
-
const transUnitRangeReversed = useMemo(() => [0, clientWidth], []);
|
|
224
|
-
const transProgress = transUnitReversed.to(transUnitRangeReversed, [0, 1], "clamp");
|
|
225
|
-
const transPercent = transUnitReversed.to(transUnitRangeReversed, [0, 100], "clamp");
|
|
226
|
-
const initThreshold = useMemo(() => Math.floor(clientWidth), []);
|
|
227
|
-
const threshold = useMemo(() => Math.floor(clientWidth / 3), []);
|
|
228
|
-
const pageState = location.pathRoute.pageState;
|
|
229
|
-
const prevPageState = prevLocation?.pathRoute.pageState ?? defaultPageState;
|
|
230
|
-
const pageClassName = "touch-pan-y";
|
|
231
|
-
useEffect(() => {
|
|
232
|
-
onBack.current.stack = async () => {
|
|
233
|
-
await transUnit.start(transUnitRange[0]);
|
|
234
|
-
};
|
|
235
|
-
}, []);
|
|
236
|
-
useEffect(() => {
|
|
237
|
-
if (history.current.type === "forward") {
|
|
238
|
-
void transUnit.start(transUnitRange[0], { immediate: true });
|
|
239
|
-
void transUnit.start(transUnitRange[1], { config: { duration: 150 } });
|
|
240
|
-
} else {
|
|
241
|
-
void transUnit.start(transUnitRange[1], { immediate: true });
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
}, [location.pathname]);
|
|
245
|
-
|
|
246
|
-
const pageBind = useDrag(
|
|
247
|
-
({ first, down, last, movement: [mx], initial: [ix], cancel }) => {
|
|
248
|
-
if (first) void device.hideKeyboard();
|
|
249
|
-
if (ix > initThreshold) {
|
|
250
|
-
cancel();
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
if (mx < transUnitRange[1]) void transUnit.start(transUnitRange[1], { immediate: true });
|
|
254
|
-
else if (mx > transUnitRange[0]) void transUnit.start(transUnitRange[0], { immediate: true });
|
|
255
|
-
else if (!last) void transUnit.start(mx, { immediate: true });
|
|
256
|
-
else if (mx < threshold) void transUnit.start(transUnitRange[1]);
|
|
257
|
-
if (last && mx > threshold) router.back();
|
|
258
|
-
},
|
|
259
|
-
{ axis: "x", filterTaps: true }
|
|
260
|
-
);
|
|
261
|
-
|
|
262
|
-
const csrTranstionStyles: CsrTransitionStyles = {
|
|
263
|
-
topSafeArea: {
|
|
264
|
-
containerStyle: {
|
|
265
|
-
height: transProgress.to([0, 1], [prevPageState.topSafeArea, pageState.topSafeArea]),
|
|
266
|
-
},
|
|
267
|
-
},
|
|
268
|
-
bottomSafeArea: {
|
|
269
|
-
containerStyle: {
|
|
270
|
-
top: transProgress.to(
|
|
271
|
-
[0, 1],
|
|
272
|
-
[clientHeight - prevPageState.bottomSafeArea, clientHeight - pageState.bottomSafeArea]
|
|
273
|
-
),
|
|
274
|
-
height: transProgress.to([0, 1], [prevPageState.bottomSafeArea, pageState.bottomSafeArea]),
|
|
275
|
-
},
|
|
276
|
-
},
|
|
277
|
-
page: {
|
|
278
|
-
containerStyle: {},
|
|
279
|
-
contentStyle: {
|
|
280
|
-
paddingTop: pageState.topSafeArea + pageState.topInset,
|
|
281
|
-
paddingBottom: pageState.bottomInset + pageState.bottomSafeArea,
|
|
282
|
-
translateX: transUnit,
|
|
283
|
-
height: clientHeight,
|
|
284
|
-
},
|
|
285
|
-
},
|
|
286
|
-
prevPage: {
|
|
287
|
-
containerStyle: {
|
|
288
|
-
paddingTop: prevPageState.topSafeArea + prevPageState.topInset,
|
|
289
|
-
translateX: transUnit.to((unit) => (unit - clientWidth) / 5),
|
|
290
|
-
},
|
|
291
|
-
contentStyle: {
|
|
292
|
-
opacity: transProgress.to((progress) => 1 - progress / 2),
|
|
293
|
-
},
|
|
294
|
-
},
|
|
295
|
-
topInset: {
|
|
296
|
-
containerStyle: {
|
|
297
|
-
top: transProgress.to([0, 1], [prevPageState.topSafeArea, pageState.topSafeArea]),
|
|
298
|
-
height: transProgress.to([0, 1], [prevPageState.topInset, pageState.topInset]),
|
|
299
|
-
},
|
|
300
|
-
contentStyle: {
|
|
301
|
-
opacity: transProgress.to((progress) => progress),
|
|
302
|
-
translateX: transProgress.to([0, 1], [clientWidth / 5, 0]),
|
|
303
|
-
},
|
|
304
|
-
prevContentStyle: {
|
|
305
|
-
opacity: transProgress.to((progress) => 1 - progress),
|
|
306
|
-
translateX: transProgress.to([0, 1], [0, -clientWidth / 5]),
|
|
307
|
-
},
|
|
308
|
-
},
|
|
309
|
-
topLeftAction: {
|
|
310
|
-
containerStyle: {
|
|
311
|
-
top: transProgress.to([0, 1], [prevPageState.topSafeArea, pageState.topSafeArea]),
|
|
312
|
-
height: transProgress.to([0, 1], [prevPageState.topInset, pageState.topInset]),
|
|
313
|
-
minWidth: transProgress.to([0, 1], [prevPageState.topInset, pageState.topInset]),
|
|
314
|
-
},
|
|
315
|
-
contentStyle: {
|
|
316
|
-
opacity: transProgress.to((progress) => progress),
|
|
317
|
-
},
|
|
318
|
-
prevContentStyle: {
|
|
319
|
-
opacity: transProgress.to((progress) => 1 - progress),
|
|
320
|
-
},
|
|
321
|
-
},
|
|
322
|
-
bottomInset: {
|
|
323
|
-
containerStyle: {
|
|
324
|
-
height: transProgress.to([0, 1], [prevPageState.bottomInset, pageState.bottomInset]),
|
|
325
|
-
top: transProgress.to(
|
|
326
|
-
[0, 1],
|
|
327
|
-
[
|
|
328
|
-
clientHeight - prevPageState.bottomInset - prevPageState.bottomSafeArea,
|
|
329
|
-
clientHeight - pageState.bottomInset - pageState.bottomSafeArea,
|
|
330
|
-
]
|
|
331
|
-
),
|
|
332
|
-
},
|
|
333
|
-
contentStyle: {
|
|
334
|
-
top: transProgress.to([0, 1], [0, -(pageState.bottomInset - prevPageState.bottomInset) * 2]),
|
|
335
|
-
opacity: transProgress.to((progress) => progress),
|
|
336
|
-
},
|
|
337
|
-
prevContentStyle: {
|
|
338
|
-
top: transProgress.to([0, 1], [0, -(pageState.bottomInset - prevPageState.bottomInset) * 2]),
|
|
339
|
-
opacity: transProgress.to((progress) => 1 - progress),
|
|
340
|
-
},
|
|
341
|
-
},
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
const useCsrTransition: UseCsrTransition = {
|
|
345
|
-
...csrTranstionStyles,
|
|
346
|
-
pageBind,
|
|
347
|
-
pageClassName,
|
|
348
|
-
transDirection,
|
|
349
|
-
transUnitRange,
|
|
350
|
-
transUnit,
|
|
351
|
-
transPercent,
|
|
352
|
-
transProgress,
|
|
353
|
-
};
|
|
354
|
-
return useCsrTransition;
|
|
355
|
-
};
|
|
356
|
-
|
|
357
|
-
const useBottomUpTrans = ({
|
|
358
|
-
clientWidth,
|
|
359
|
-
clientHeight,
|
|
360
|
-
history,
|
|
361
|
-
location,
|
|
362
|
-
prevLocation,
|
|
363
|
-
onBack,
|
|
364
|
-
}: RouteState): UseCsrTransition => {
|
|
365
|
-
const transDirection = "vertical";
|
|
366
|
-
const transUnit = useSpringValue(0, { config: { clamp: true } });
|
|
367
|
-
const transUnitRange = useMemo(() => [clientHeight, 0], []);
|
|
368
|
-
const transUnitReversed = transUnit.to((unit) => transUnitRange[0] - unit);
|
|
369
|
-
const transUnitRangeReversed = useMemo(() => [0, clientWidth], []);
|
|
370
|
-
const transProgress = transUnitReversed.to(transUnitRangeReversed, [0, 1], "clamp");
|
|
371
|
-
const transPercent = transUnitReversed.to(transUnitRangeReversed, [0, 100], "clamp");
|
|
372
|
-
const initThreshold = useMemo(() => Math.floor(clientWidth / 3), []);
|
|
373
|
-
const threshold = useMemo(() => Math.floor(clientWidth / 2), []);
|
|
374
|
-
const pageState = location.pathRoute.pageState;
|
|
375
|
-
const prevPageState = prevLocation?.pathRoute.pageState ?? defaultPageState;
|
|
376
|
-
useEffect(() => {
|
|
377
|
-
onBack.current.bottomUp = async () => {
|
|
378
|
-
await transUnit.start(transUnitRange[0]);
|
|
379
|
-
};
|
|
380
|
-
}, []);
|
|
381
|
-
useEffect(() => {
|
|
382
|
-
if (history.current.type === "forward") {
|
|
383
|
-
void transUnit.start(transUnitRange[0], { immediate: true });
|
|
384
|
-
void transUnit.start(transUnitRange[1], { config: { duration: 150 } });
|
|
385
|
-
} else {
|
|
386
|
-
void transUnit.start(transUnitRange[1], { immediate: true });
|
|
387
|
-
return;
|
|
388
|
-
}
|
|
389
|
-
}, [location.pathname]);
|
|
390
|
-
|
|
391
|
-
const pageBind = useDrag(
|
|
392
|
-
({ first, last, movement: [, my], initial: [, iy], cancel }) => {
|
|
393
|
-
if (first) void device.hideKeyboard();
|
|
394
|
-
if (iy > initThreshold) {
|
|
395
|
-
cancel();
|
|
396
|
-
return;
|
|
397
|
-
}
|
|
398
|
-
if (my < transUnitRange[1]) void transUnit.start(transUnitRange[1], { immediate: true });
|
|
399
|
-
else if (my > transUnitRange[0]) void transUnit.start(transUnitRange[0], { immediate: true });
|
|
400
|
-
else if (!last) void transUnit.start(my, { immediate: true });
|
|
401
|
-
else if (my < threshold) void transUnit.start(transUnitRange[1]);
|
|
402
|
-
if (last && my > threshold) router.back();
|
|
403
|
-
},
|
|
404
|
-
{ axis: "y", filterTaps: true, threshold: 10 }
|
|
405
|
-
);
|
|
406
|
-
|
|
407
|
-
const csrTranstionStyles: CsrTransitionStyles = {
|
|
408
|
-
topSafeArea: {
|
|
409
|
-
containerStyle: {
|
|
410
|
-
height: transProgress.to([0, 1], [prevPageState.topSafeArea, pageState.topSafeArea]),
|
|
411
|
-
},
|
|
412
|
-
},
|
|
413
|
-
bottomSafeArea: {
|
|
414
|
-
containerStyle: {
|
|
415
|
-
top: transProgress.to(
|
|
416
|
-
[0, 1],
|
|
417
|
-
[clientHeight - prevPageState.bottomSafeArea, clientHeight - pageState.bottomSafeArea]
|
|
418
|
-
),
|
|
419
|
-
height: transProgress.to([0, 1], [prevPageState.bottomSafeArea, pageState.bottomSafeArea]),
|
|
420
|
-
},
|
|
421
|
-
},
|
|
422
|
-
page: {
|
|
423
|
-
containerStyle: {},
|
|
424
|
-
contentStyle: {
|
|
425
|
-
paddingTop: pageState.topSafeArea + pageState.topInset,
|
|
426
|
-
paddingBottom: pageState.bottomInset + pageState.bottomSafeArea,
|
|
427
|
-
translateY: transUnit,
|
|
428
|
-
height: clientHeight,
|
|
429
|
-
},
|
|
430
|
-
},
|
|
431
|
-
prevPage: {
|
|
432
|
-
containerStyle: {
|
|
433
|
-
paddingTop: prevPageState.topSafeArea + prevPageState.topInset,
|
|
434
|
-
translateY: 0,
|
|
435
|
-
},
|
|
436
|
-
contentStyle: {
|
|
437
|
-
opacity: transProgress.to((progress) => 1 - progress / 2),
|
|
438
|
-
},
|
|
439
|
-
},
|
|
440
|
-
topInset: {
|
|
441
|
-
containerStyle: {
|
|
442
|
-
top: transProgress.to([0, 1], [prevPageState.topSafeArea, pageState.topSafeArea]),
|
|
443
|
-
height: transProgress.to([0, 1], [prevPageState.topInset, pageState.topInset]),
|
|
444
|
-
},
|
|
445
|
-
contentStyle: {
|
|
446
|
-
opacity: transProgress.to((progress) => progress),
|
|
447
|
-
// translateX: transProgress.to([0, 1], [clientWidth / 5, 0]),
|
|
448
|
-
},
|
|
449
|
-
prevContentStyle: {
|
|
450
|
-
opacity: transProgress.to((progress) => 1 - progress),
|
|
451
|
-
// translateX: transProgress.to([0, 1], [0, -clientWidth / 5]),
|
|
452
|
-
},
|
|
453
|
-
},
|
|
454
|
-
topLeftAction: {
|
|
455
|
-
containerStyle: {
|
|
456
|
-
top: transProgress.to([0, 1], [prevPageState.topSafeArea, pageState.topSafeArea]),
|
|
457
|
-
height: transProgress.to([0, 1], [prevPageState.topInset, pageState.topInset]),
|
|
458
|
-
},
|
|
459
|
-
contentStyle: {
|
|
460
|
-
opacity: transProgress.to((progress) => progress),
|
|
461
|
-
},
|
|
462
|
-
prevContentStyle: {
|
|
463
|
-
opacity: transProgress.to((progress) => 1 - progress),
|
|
464
|
-
},
|
|
465
|
-
},
|
|
466
|
-
bottomInset: {
|
|
467
|
-
containerStyle: {
|
|
468
|
-
height: transProgress.to([0, 1], [prevPageState.bottomInset, pageState.bottomInset]),
|
|
469
|
-
top: transProgress.to(
|
|
470
|
-
[0, 1],
|
|
471
|
-
[
|
|
472
|
-
clientHeight - prevPageState.bottomInset - prevPageState.bottomSafeArea,
|
|
473
|
-
clientHeight - pageState.bottomInset - pageState.bottomSafeArea,
|
|
474
|
-
]
|
|
475
|
-
),
|
|
476
|
-
},
|
|
477
|
-
contentStyle: {
|
|
478
|
-
top: transProgress.to([0, 1], [0, -(pageState.bottomInset - prevPageState.bottomInset) * 2]),
|
|
479
|
-
opacity: transProgress.to((progress) => progress),
|
|
480
|
-
},
|
|
481
|
-
prevContentStyle: {
|
|
482
|
-
top: transProgress.to([0, 1], [0, -(pageState.bottomInset - prevPageState.bottomInset) * 2]),
|
|
483
|
-
opacity: transProgress.to((progress) => 1 - progress),
|
|
484
|
-
},
|
|
485
|
-
},
|
|
486
|
-
};
|
|
487
|
-
|
|
488
|
-
const useCsrTransition: UseCsrTransition = {
|
|
489
|
-
...csrTranstionStyles,
|
|
490
|
-
pageBind,
|
|
491
|
-
pageClassName: "touch-pan-x",
|
|
492
|
-
transDirection,
|
|
493
|
-
transUnitRange,
|
|
494
|
-
transUnit,
|
|
495
|
-
transPercent,
|
|
496
|
-
transProgress,
|
|
497
|
-
};
|
|
498
|
-
return useCsrTransition;
|
|
499
|
-
};
|
|
500
|
-
|
|
501
|
-
export const useCsrValues = (rootRouteGuide: RouteGuide, pathRoutes: PathRoute[]) => {
|
|
502
|
-
const clientWidth = useRef(window.innerWidth);
|
|
503
|
-
const clientHeight = useRef(window.innerHeight);
|
|
504
|
-
const topSafeAreaRef = useRef<HTMLDivElement>(null);
|
|
505
|
-
const bottomSafeAreaRef = useRef<HTMLDivElement>(null);
|
|
506
|
-
const pageContentRef = useRef<HTMLDivElement>(null);
|
|
507
|
-
const prevPageContentRef = useRef<HTMLDivElement>(null);
|
|
508
|
-
const onBack = useRef<{ [K in TransitionType]?: () => Promise<void> }>({});
|
|
509
|
-
const frameRootRef = useRef<HTMLDivElement>(null);
|
|
510
|
-
|
|
511
|
-
const { getLocation } = useLocation({ rootRouteGuide });
|
|
512
|
-
const { history, setHistoryForward, setHistoryBack, getCurrentLocation, getPrevLocation, getScrollTop } = useHistory([
|
|
513
|
-
getLocation(window.location.pathname),
|
|
514
|
-
]);
|
|
515
|
-
const [{ location, prevLocation }, setLocationState] = useState<LocationState>({
|
|
516
|
-
location: getCurrentLocation(),
|
|
517
|
-
prevLocation: getPrevLocation(),
|
|
518
|
-
});
|
|
519
|
-
const getRouter = useCallback((): RouterInstance => {
|
|
520
|
-
const router = {
|
|
521
|
-
push: (href: string) => {
|
|
522
|
-
const location = getCurrentLocation();
|
|
523
|
-
const scrollTop = pageContentRef.current?.scrollTop ?? 0;
|
|
524
|
-
setHistoryForward({ type: "push", location: getLocation(href), scrollTop });
|
|
525
|
-
setLocationState({ location: getCurrentLocation(), prevLocation: location });
|
|
526
|
-
window.history.pushState({}, "", href);
|
|
527
|
-
},
|
|
528
|
-
replace: (href: string) => {
|
|
529
|
-
const scrollTop = pageContentRef.current?.scrollTop ?? 0;
|
|
530
|
-
setHistoryForward({ type: "replace", location: getLocation(href), scrollTop });
|
|
531
|
-
setLocationState({ location: getCurrentLocation(), prevLocation });
|
|
532
|
-
window.history.replaceState({}, "", href);
|
|
533
|
-
},
|
|
534
|
-
refresh: () => {
|
|
535
|
-
window.location.reload();
|
|
536
|
-
},
|
|
537
|
-
back: async () => {
|
|
538
|
-
const location = getCurrentLocation();
|
|
539
|
-
await onBack.current[location.pathRoute.pageState.transition]?.();
|
|
540
|
-
const scrollTop = pageContentRef.current?.scrollTop ?? 0;
|
|
541
|
-
setHistoryBack({ type: "back", location, scrollTop });
|
|
542
|
-
setLocationState({ location: getCurrentLocation(), prevLocation: getPrevLocation() });
|
|
543
|
-
window.history.back();
|
|
544
|
-
},
|
|
545
|
-
};
|
|
546
|
-
window.onpopstate = async (ev: PopStateEvent) => {
|
|
547
|
-
const routeType =
|
|
548
|
-
window.location.pathname === getCurrentLocation().pathname && history.current.type !== "back"
|
|
549
|
-
? "forward"
|
|
550
|
-
: window.location.pathname === getPrevLocation()?.pathname
|
|
551
|
-
? "back"
|
|
552
|
-
: null;
|
|
553
|
-
const scrollTop = pageContentRef.current?.scrollTop ?? 0;
|
|
554
|
-
if (!routeType) return;
|
|
555
|
-
if (routeType === "forward") {
|
|
556
|
-
const location = getCurrentLocation();
|
|
557
|
-
setHistoryForward({ type: "popForward", location, scrollTop });
|
|
558
|
-
setLocationState({ location: getCurrentLocation(), prevLocation: location });
|
|
559
|
-
} else {
|
|
560
|
-
// back
|
|
561
|
-
const location = getCurrentLocation();
|
|
562
|
-
await onBack.current[location.pathRoute.pageState.transition]?.();
|
|
563
|
-
setHistoryBack({ type: "popBack", location, scrollTop });
|
|
564
|
-
setLocationState({ location: getCurrentLocation(), prevLocation: getPrevLocation() });
|
|
565
|
-
}
|
|
566
|
-
};
|
|
567
|
-
return router;
|
|
568
|
-
}, [location]);
|
|
569
|
-
const router = getRouter();
|
|
570
|
-
const routeState: RouteState = {
|
|
571
|
-
clientWidth: clientWidth.current,
|
|
572
|
-
clientHeight: clientHeight.current,
|
|
573
|
-
location,
|
|
574
|
-
prevLocation,
|
|
575
|
-
history,
|
|
576
|
-
topSafeAreaRef,
|
|
577
|
-
bottomSafeAreaRef,
|
|
578
|
-
prevPageContentRef,
|
|
579
|
-
pageContentRef,
|
|
580
|
-
frameRootRef,
|
|
581
|
-
onBack,
|
|
582
|
-
router,
|
|
583
|
-
pathRoutes,
|
|
584
|
-
};
|
|
585
|
-
const useNonTransition = useNoneTrans(routeState);
|
|
586
|
-
const useFadeTransition = useFadeTrans(routeState);
|
|
587
|
-
const useStackTransition = useStackTrans(routeState);
|
|
588
|
-
const useBottomUpTransition = useBottomUpTrans(routeState);
|
|
589
|
-
const useCsrTransitionMap: { [key in TransitionType]: UseCsrTransition } = {
|
|
590
|
-
none: useNonTransition,
|
|
591
|
-
fade: useFadeTransition,
|
|
592
|
-
stack: useStackTransition,
|
|
593
|
-
bottomUp: useBottomUpTransition,
|
|
594
|
-
scaleOut: useNonTransition,
|
|
595
|
-
};
|
|
596
|
-
|
|
597
|
-
useEffect(() => {
|
|
598
|
-
if (pageContentRef.current) pageContentRef.current.scrollTop = getScrollTop(location.pathname);
|
|
599
|
-
if (prevPageContentRef.current)
|
|
600
|
-
prevPageContentRef.current.scrollTop = prevLocation ? getScrollTop(prevLocation.pathname) : 0;
|
|
601
|
-
void App.addListener("backButton", () => {
|
|
602
|
-
router.back();
|
|
603
|
-
});
|
|
604
|
-
return () => {
|
|
605
|
-
void App.removeAllListeners();
|
|
606
|
-
};
|
|
607
|
-
}, [location.pathname]);
|
|
608
|
-
|
|
609
|
-
return {
|
|
610
|
-
...routeState,
|
|
611
|
-
...useCsrTransitionMap[location.pathRoute.pageState.transition],
|
|
612
|
-
} satisfies CsrContextType;
|
|
613
|
-
};
|
package/useDebounce.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useCallback } from "react";
|
|
3
|
-
|
|
4
|
-
const debounce = <Callback extends (...args: any) => any>(callback: Callback, wait = 500) => {
|
|
5
|
-
// 실행한 함수(setTimeout())를 취소
|
|
6
|
-
let timer: NodeJS.Timeout;
|
|
7
|
-
return ((...args: object[]) => {
|
|
8
|
-
clearTimeout(timer);
|
|
9
|
-
// delay가 지나면 callback 함수를 실행
|
|
10
|
-
timer = setTimeout(() => {
|
|
11
|
-
callback(...args);
|
|
12
|
-
}, wait);
|
|
13
|
-
}) as Callback;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const useDebounce = <Callback extends (...args: any) => any>(
|
|
17
|
-
callback: Callback,
|
|
18
|
-
states: any[] = [],
|
|
19
|
-
wait = 100
|
|
20
|
-
) => {
|
|
21
|
-
const fn = useCallback(debounce(callback, wait), states);
|
|
22
|
-
return fn;
|
|
23
|
-
};
|
package/useFetch.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useEffect, useState } from "react";
|
|
3
|
-
|
|
4
|
-
export const useFetch = <Return>(
|
|
5
|
-
fnOrPromise: Promise<Return> | Return,
|
|
6
|
-
{ onError }: { onError?: (err: string) => void } = {}
|
|
7
|
-
): { fulfilled: boolean; value: Return | null } => {
|
|
8
|
-
const [fetchState, setFetchState] = useState<{ fulfilled: boolean; value: any }>(
|
|
9
|
-
fnOrPromise instanceof Promise ? { fulfilled: false, value: null } : { fulfilled: true, value: fnOrPromise }
|
|
10
|
-
);
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
void (async () => {
|
|
13
|
-
try {
|
|
14
|
-
const ret = fnOrPromise instanceof Promise ? await fnOrPromise : fnOrPromise;
|
|
15
|
-
setFetchState({ fulfilled: true, value: ret });
|
|
16
|
-
} catch (err) {
|
|
17
|
-
const content = `Error: ${typeof err === "string" ? err : (err as Error).message}`;
|
|
18
|
-
onError?.(content);
|
|
19
|
-
throw new Error(content);
|
|
20
|
-
}
|
|
21
|
-
})();
|
|
22
|
-
}, []);
|
|
23
|
-
return fetchState;
|
|
24
|
-
};
|