Skip to content

Commit

Permalink
fix: close motion not finished (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ authored Feb 23, 2021
1 parent 8804de4 commit 41ad303
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
rules: {
'default-case': 0,
'import/no-extraneous-dependencies': 0,
'react-hooks/exhaustive-deps': 0,
'react/no-find-dom-node': 0,
'react/no-did-update-set-state': 0,
'react/no-unused-state': 1,
Expand Down
13 changes: 11 additions & 2 deletions src/Popup/useVisibleStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@ export default (
visible: boolean,
doMeasure: Func,
): [PopupStatus, (callback?: () => void) => void] => {
const [status, setStatus] = useState<PopupStatus>(null);
const [status, setInternalStatus] = useState<PopupStatus>(null);
const rafRef = useRef<number>();
const destroyRef = useRef(false);

function setStatus(
nextStatus: PopupStatus | ((prevStatus: PopupStatus) => PopupStatus),
) {
if (!destroyRef.current) {
setInternalStatus(nextStatus);
}
}

function cancelRaf() {
raf.cancel(rafRef.current);
Expand Down Expand Up @@ -63,7 +72,6 @@ export default (
}

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

useEffect(
() => () => {
destroyRef.current = true;
cancelRaf();
},
[],
Expand Down

0 comments on commit 41ad303

Please sign in to comment.