@cher1shrxd/webview-stack-kit 1.0.0 → 1.0.2
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/dist/components/NavigationStack.d.ts.map +1 -1
- package/dist/components/NavigationStack.js +1 -16
- package/dist/components/NavigationStackView.d.ts.map +1 -1
- package/dist/components/NavigationStackView.js +22 -1
- package/dist/components/StackScreen.d.ts.map +1 -1
- package/dist/components/StackScreen.js +1 -22
- package/dist/context/stack-reducer.d.ts.map +1 -1
- package/dist/context/stack-reducer.js +0 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NavigationStack.d.ts","sourceRoot":"","sources":["../../src/components/NavigationStack.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"NavigationStack.d.ts","sourceRoot":"","sources":["../../src/components/NavigationStack.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAI1C,eAAO,MAAM,eAAe,GAAI,cAAc,iBAAiB,4CAO9D,CAAC"}
|
|
@@ -1,22 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useEffect, useState } from "react";
|
|
4
3
|
import { StackProvider } from "../context/stack-provider";
|
|
5
4
|
import { NavigationStackView } from "./NavigationStackView";
|
|
6
|
-
import { getSearchParams } from "../utils/get-search-params";
|
|
7
5
|
export const NavigationStack = ({ children }) => {
|
|
8
|
-
|
|
9
|
-
paddingTop: 0,
|
|
10
|
-
paddingBottom: 0,
|
|
11
|
-
});
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
const searchParams = getSearchParams();
|
|
14
|
-
const topPadding = Number(searchParams["top"] || 0);
|
|
15
|
-
const bottomPadding = Number(searchParams["bottom"] || 0);
|
|
16
|
-
setDynamicPadding({ paddingTop: topPadding, paddingBottom: bottomPadding });
|
|
17
|
-
}, []);
|
|
18
|
-
return (_jsxs(StackProvider, { children: [_jsx(NavigationStackView, {}), _jsx("div", { style: {
|
|
19
|
-
paddingTop: dynamicPadding.paddingTop,
|
|
20
|
-
paddingBottom: dynamicPadding.paddingBottom,
|
|
21
|
-
}, children: children })] }));
|
|
6
|
+
return (_jsxs(StackProvider, { children: [_jsx(NavigationStackView, {}), children] }));
|
|
22
7
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NavigationStackView.d.ts","sourceRoot":"","sources":["../../src/components/NavigationStackView.tsx"],"names":[],"mappings":"AAOA,eAAO,MAAM,mBAAmB,+
|
|
1
|
+
{"version":3,"file":"NavigationStackView.d.ts","sourceRoot":"","sources":["../../src/components/NavigationStackView.tsx"],"names":[],"mappings":"AAOA,eAAO,MAAM,mBAAmB,+CA4H/B,CAAC"}
|
|
@@ -7,6 +7,20 @@ export const NavigationStackView = () => {
|
|
|
7
7
|
const { stack, pop, remove } = useStack();
|
|
8
8
|
const topScreenRef = useRef(null);
|
|
9
9
|
const dragInfo = useRef(null);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const handlePopState = (e) => {
|
|
12
|
+
e.preventDefault?.();
|
|
13
|
+
if (stack.length > 1) {
|
|
14
|
+
pop();
|
|
15
|
+
window.history.pushState(null, '', window.location.href);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
window.history.pushState(null, '', window.location.href);
|
|
19
|
+
window.addEventListener('popstate', handlePopState);
|
|
20
|
+
return () => {
|
|
21
|
+
window.removeEventListener('popstate', handlePopState);
|
|
22
|
+
};
|
|
23
|
+
}, [stack.length, pop]);
|
|
10
24
|
const handleDragEnd = useCallback(() => {
|
|
11
25
|
if (!dragInfo.current?.isDragging)
|
|
12
26
|
return;
|
|
@@ -35,9 +49,12 @@ export const NavigationStackView = () => {
|
|
|
35
49
|
else {
|
|
36
50
|
clientX = e.clientX;
|
|
37
51
|
}
|
|
52
|
+
const distance = clientX - dragInfo.current.startX;
|
|
53
|
+
if (distance < 0)
|
|
54
|
+
return;
|
|
38
55
|
dragInfo.current.lastX = clientX;
|
|
39
56
|
if (topScreenRef.current) {
|
|
40
|
-
topScreenRef.current.style.transform = `translateX(${
|
|
57
|
+
topScreenRef.current.style.transform = `translateX(${distance}px)`;
|
|
41
58
|
}
|
|
42
59
|
}, []);
|
|
43
60
|
const handleDragStart = useCallback((e, index) => {
|
|
@@ -52,6 +69,10 @@ export const NavigationStackView = () => {
|
|
|
52
69
|
else {
|
|
53
70
|
clientX = e.clientX;
|
|
54
71
|
}
|
|
72
|
+
// 화면 왼쪽 가장자리에서만 스와이프 시작 허용 (왼쪽 20% 이내)
|
|
73
|
+
const screenWidth = window.innerWidth;
|
|
74
|
+
if (clientX > screenWidth * 0.2)
|
|
75
|
+
return;
|
|
55
76
|
dragInfo.current = {
|
|
56
77
|
isDragging: true,
|
|
57
78
|
startX: clientX,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StackScreen.d.ts","sourceRoot":"","sources":["../../src/components/StackScreen.tsx"],"names":[],"mappings":"AAAA,OAAO,EAOL,UAAU,EACV,UAAU,EACX,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"StackScreen.d.ts","sourceRoot":"","sources":["../../src/components/StackScreen.tsx"],"names":[],"mappings":"AAAA,OAAO,EAOL,UAAU,EACV,UAAU,EACX,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAgBrC,eAAO,MAAM,WAAW;;UAGd,SAAS;WACR,MAAM;gBACD,MAAM;oBACF,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI;iBACvB,CAAC,CAAC,EAAE,UAAU,GAAG,UAAU,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI;0DAwDlE,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useState, useEffect, forwardRef, useRef,
|
|
3
|
-
import { getSearchParams } from "../utils/get-search-params";
|
|
2
|
+
import { useState, useEffect, forwardRef, useRef, } from "react";
|
|
4
3
|
const stackScreenStyle = {
|
|
5
4
|
position: "absolute",
|
|
6
5
|
top: 0,
|
|
@@ -16,21 +15,8 @@ const stackScreenStyle = {
|
|
|
16
15
|
};
|
|
17
16
|
export const StackScreen = forwardRef(({ item, index, totalCount, onExitComplete, onDragStart, ...rest }, ref) => {
|
|
18
17
|
const [isMounted, setIsMounted] = useState(false);
|
|
19
|
-
const [dynamicPadding, setDynamicPadding] = useState({
|
|
20
|
-
paddingTop: 0,
|
|
21
|
-
paddingBottom: 0,
|
|
22
|
-
});
|
|
23
18
|
const isExiting = item.transition === "pop";
|
|
24
19
|
const containerRef = useRef(null);
|
|
25
|
-
useLayoutEffect(() => {
|
|
26
|
-
const elList = containerRef.current?.querySelectorAll(".stack-view");
|
|
27
|
-
if (!elList)
|
|
28
|
-
return;
|
|
29
|
-
elList.forEach((el) => {
|
|
30
|
-
el.style.paddingTop = `${dynamicPadding.paddingTop}px`;
|
|
31
|
-
el.style.paddingBottom = `${dynamicPadding.paddingBottom}px`;
|
|
32
|
-
});
|
|
33
|
-
}, [dynamicPadding.paddingTop, dynamicPadding.paddingBottom]);
|
|
34
20
|
useEffect(() => {
|
|
35
21
|
const frame = requestAnimationFrame(() => {
|
|
36
22
|
setIsMounted(true);
|
|
@@ -45,13 +31,6 @@ export const StackScreen = forwardRef(({ item, index, totalCount, onExitComplete
|
|
|
45
31
|
return () => clearTimeout(timer);
|
|
46
32
|
}
|
|
47
33
|
}, [isExiting, item.id, onExitComplete]);
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
const searchParams = getSearchParams();
|
|
50
|
-
setDynamicPadding({
|
|
51
|
-
paddingTop: Number(searchParams["top"] || 0),
|
|
52
|
-
paddingBottom: Number(searchParams["bottom"] || 0),
|
|
53
|
-
});
|
|
54
|
-
}, []);
|
|
55
34
|
const isTop = index === totalCount - 1;
|
|
56
35
|
const style = {
|
|
57
36
|
...stackScreenStyle,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stack-reducer.d.ts","sourceRoot":"","sources":["../../src/context/stack-reducer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAElD,eAAO,MAAM,YAAY,GAAI,OAAO,UAAU,EAAE,QAAQ,WAAW,KAAG,
|
|
1
|
+
{"version":3,"file":"stack-reducer.d.ts","sourceRoot":"","sources":["../../src/context/stack-reducer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAElD,eAAO,MAAM,YAAY,GAAI,OAAO,UAAU,EAAE,QAAQ,WAAW,KAAG,UAoBrE,CAAA"}
|