page-transition 0.1.0-beta.5 → 0.1.0-beta.7
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/README.md +3 -1
- package/dist/context/CssTransitionProvider.js +9 -1
- package/dist/functions/checkTransitionStart.d.ts +6 -0
- package/dist/functions/checkTransitionStart.js +15 -0
- package/dist/functions/pollTransitionStart.d.ts +12 -0
- package/dist/functions/pollTransitionStart.js +9 -0
- package/dist/hooks/useHandleLinkClick.js +12 -2
- package/dist/hooks/usePopState.js +10 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ import { useHandleLinkClick } from "../hooks/useHandleLinkClick";
|
|
|
11
11
|
import { useScrollRestoration } from "../hooks/useScrollRestoration";
|
|
12
12
|
import { usePopState } from "../hooks/usePopState";
|
|
13
13
|
import { parseDelay } from "../functions/parseDelay";
|
|
14
|
+
import { pollTransitionStart } from "../functions/pollTransitionStart";
|
|
14
15
|
export function CssTransitionProvider({ header, options, children }) {
|
|
15
16
|
const defaultOptions = {
|
|
16
17
|
transitionProperty: 'opacity',
|
|
@@ -50,6 +51,7 @@ export function CssTransitionProvider({ header, options, children }) {
|
|
|
50
51
|
elArray: defaultOptions.overlayCount === 0 ? container : overlayItems,
|
|
51
52
|
transitionProperty: defaultOptions.transitionProperty
|
|
52
53
|
});
|
|
54
|
+
const pollRafId = useRef(null);
|
|
53
55
|
usePopState({
|
|
54
56
|
container,
|
|
55
57
|
currentPathname,
|
|
@@ -101,8 +103,14 @@ export function CssTransitionProvider({ header, options, children }) {
|
|
|
101
103
|
});
|
|
102
104
|
container.current.classList.remove('exit');
|
|
103
105
|
container.current.classList.add('enter');
|
|
106
|
+
pollTransitionStart({
|
|
107
|
+
transitionEndData,
|
|
108
|
+
id: pollRafId,
|
|
109
|
+
fn: () => {
|
|
110
|
+
state.current = 'entering';
|
|
111
|
+
}
|
|
112
|
+
});
|
|
104
113
|
currentPathname.current = pathname;
|
|
105
|
-
state.current = 'entering';
|
|
106
114
|
reverse.current.lock = false;
|
|
107
115
|
}, [pathname]);
|
|
108
116
|
const value = useMemo(() => ({ handleLinkClick, overlayWrapper, overlayItems }), []);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { parseOpacityAll } from "./parseOpacityAll";
|
|
2
|
+
import { parseClipPathAll } from "./parseClipPathAll";
|
|
3
|
+
export function checkTransitionStart(transitionEndData, fn) {
|
|
4
|
+
const parse = {
|
|
5
|
+
'opacity': () => parseOpacityAll(transitionEndData.elArray),
|
|
6
|
+
'clip-path': () => parseClipPathAll(transitionEndData.elArray)
|
|
7
|
+
};
|
|
8
|
+
if (parse[transitionEndData.propertyName]()) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
fn?.();
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RefObject } from "react";
|
|
2
|
+
interface TransitionEndData {
|
|
3
|
+
elArray: (HTMLDivElement | null)[];
|
|
4
|
+
propertyName: 'opacity' | 'clip-path';
|
|
5
|
+
}
|
|
6
|
+
interface Props {
|
|
7
|
+
id: RefObject<number | null>;
|
|
8
|
+
fn: () => void;
|
|
9
|
+
transitionEndData: RefObject<TransitionEndData>;
|
|
10
|
+
}
|
|
11
|
+
export declare function pollTransitionStart({ id, fn, transitionEndData }: Props): void;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { checkTransitionStart } from "./checkTransitionStart";
|
|
2
|
+
export function pollTransitionStart({ id, fn, transitionEndData }) {
|
|
3
|
+
id.current = requestAnimationFrame(() => {
|
|
4
|
+
if (checkTransitionStart(transitionEndData.current, fn)) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
pollTransitionStart({ id, fn, transitionEndData });
|
|
8
|
+
});
|
|
9
|
+
}
|
|
@@ -4,10 +4,12 @@ import { useRouter } from "next/navigation";
|
|
|
4
4
|
import { useTransitionEndObj } from "../hooks/useTransitionEndObj";
|
|
5
5
|
import { transitionEnd } from "../functions/transitionEnd";
|
|
6
6
|
import { checkTransitionFinish } from "../functions/checkTransitionFinish";
|
|
7
|
+
import { pollTransitionStart } from "../functions/pollTransitionStart";
|
|
7
8
|
export function useHandleLinkClick({ container, handleLinkClick, currentPathname, transitionEndData, transitionEndHandler, reverse, delay, state, useUse, resolveUseFn }) {
|
|
8
9
|
const router = useRouter();
|
|
9
10
|
const afterExitFn = useRef(null);
|
|
10
11
|
const nextPage = useRef(null);
|
|
12
|
+
const pollRafId = useRef(null);
|
|
11
13
|
const push = useTransitionEndObj({
|
|
12
14
|
transitionEndData,
|
|
13
15
|
fn: () => {
|
|
@@ -42,10 +44,17 @@ export function useHandleLinkClick({ container, handleLinkClick, currentPathname
|
|
|
42
44
|
state.current = 'navigating';
|
|
43
45
|
router.push(currentPathname.current);
|
|
44
46
|
}
|
|
47
|
+
state.current = 'navigating';
|
|
45
48
|
container.current?.classList.remove('exit');
|
|
46
49
|
container.current?.classList.add('enter');
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
pollTransitionStart({
|
|
51
|
+
transitionEndData,
|
|
52
|
+
id: pollRafId,
|
|
53
|
+
fn: () => {
|
|
54
|
+
state.current = 'entering';
|
|
55
|
+
reverse.current.lock = false;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
49
58
|
}
|
|
50
59
|
});
|
|
51
60
|
handleLinkClick.current = useCallback((e, url) => {
|
|
@@ -53,6 +62,7 @@ export function useHandleLinkClick({ container, handleLinkClick, currentPathname
|
|
|
53
62
|
nextPage.current = url;
|
|
54
63
|
new Promise((resolve) => {
|
|
55
64
|
if (state.current === 'navigating') {
|
|
65
|
+
console.log('state.current === navigating');
|
|
56
66
|
if (url === currentPathname.current) {
|
|
57
67
|
return;
|
|
58
68
|
}
|
|
@@ -3,8 +3,10 @@ import { useEffect, useRef, useState, use } from "react";
|
|
|
3
3
|
import { useTransitionEndObj } from "./useTransitionEndObj";
|
|
4
4
|
import { transitionEnd } from "../functions/transitionEnd";
|
|
5
5
|
import { checkTransitionFinish } from "../functions/checkTransitionFinish";
|
|
6
|
+
import { pollTransitionStart } from "../functions/pollTransitionStart";
|
|
6
7
|
export function usePopState({ container, currentPathname, transitionEndData, transitionEndHandler, reverse, delay, state, useUse, resolveUseFn }) {
|
|
7
8
|
const [promise, setPromise] = useState(null);
|
|
9
|
+
const pollRafId = useRef(null);
|
|
8
10
|
if (promise) {
|
|
9
11
|
useUse.current = true;
|
|
10
12
|
use(promise);
|
|
@@ -31,9 +33,16 @@ export function usePopState({ container, currentPathname, transitionEndData, tra
|
|
|
31
33
|
reverse,
|
|
32
34
|
delay
|
|
33
35
|
});
|
|
36
|
+
state.current = 'navigating';
|
|
34
37
|
container.current?.classList.remove('exit');
|
|
35
38
|
container.current?.classList.add('enter');
|
|
36
|
-
|
|
39
|
+
pollTransitionStart({
|
|
40
|
+
transitionEndData,
|
|
41
|
+
id: pollRafId,
|
|
42
|
+
fn: () => {
|
|
43
|
+
state.current = 'entering';
|
|
44
|
+
}
|
|
45
|
+
});
|
|
37
46
|
reverse.current.lock = false;
|
|
38
47
|
resolveFn.current?.();
|
|
39
48
|
setPromise(null);
|