Skip to content

Commit 41ad303

Browse files
authored
fix: close motion not finished (#242)
1 parent 8804de4 commit 41ad303

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module.exports = {
33
rules: {
44
'default-case': 0,
55
'import/no-extraneous-dependencies': 0,
6+
'react-hooks/exhaustive-deps': 0,
67
'react/no-find-dom-node': 0,
78
'react/no-did-update-set-state': 0,
89
'react/no-unused-state': 1,

src/Popup/useVisibleStatus.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,17 @@ export default (
2121
visible: boolean,
2222
doMeasure: Func,
2323
): [PopupStatus, (callback?: () => void) => void] => {
24-
const [status, setStatus] = useState<PopupStatus>(null);
24+
const [status, setInternalStatus] = useState<PopupStatus>(null);
2525
const rafRef = useRef<number>();
26+
const destroyRef = useRef(false);
27+
28+
function setStatus(
29+
nextStatus: PopupStatus | ((prevStatus: PopupStatus) => PopupStatus),
30+
) {
31+
if (!destroyRef.current) {
32+
setInternalStatus(nextStatus);
33+
}
34+
}
2635

2736
function cancelRaf() {
2837
raf.cancel(rafRef.current);
@@ -63,7 +72,6 @@ export default (
6372
}
6473

6574
if (status) {
66-
cancelRaf();
6775
rafRef.current = raf(async () => {
6876
const index = StatusQueue.indexOf(status);
6977
const nextStatus = StatusQueue[index + 1];
@@ -76,6 +84,7 @@ export default (
7684

7785
useEffect(
7886
() => () => {
87+
destroyRef.current = true;
7988
cancelRaf();
8089
},
8190
[],

0 commit comments

Comments
 (0)