page-transition 0.1.0-beta.5 → 0.1.0-beta.6
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 +1 -0
- 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
|
+
}
|
|
@@ -53,6 +53,7 @@ export function useHandleLinkClick({ container, handleLinkClick, currentPathname
|
|
|
53
53
|
nextPage.current = url;
|
|
54
54
|
new Promise((resolve) => {
|
|
55
55
|
if (state.current === 'navigating') {
|
|
56
|
+
console.log('state.current === navigating');
|
|
56
57
|
if (url === currentPathname.current) {
|
|
57
58
|
return;
|
|
58
59
|
}
|