forked from glaserL/viasp
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of https://github.com/potassco/viasp into BUG/robots
- Loading branch information
Showing
7 changed files
with
98 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from "react"; | ||
import * as Constants from "../constants"; | ||
import debounce from "lodash/debounce"; | ||
import { useAnimationUpdater } from "../contexts/AnimationUpdater"; | ||
import useResizeObserver from '@react-hook/resize-observer'; | ||
|
||
|
||
export const useDebouncedAnimateResize = (elementRef, elementIdRef) => { | ||
const {setAnimationState} = useAnimationUpdater(); | ||
const setAnimationStateRef = React.useRef(setAnimationState); | ||
const animateResize = React.useCallback( | ||
(key, entry) => { | ||
const setAnimationState = setAnimationStateRef.current; | ||
setAnimationState((oldValue) => ({ | ||
...oldValue, | ||
[key]: entry.contentRect, | ||
})); | ||
}, []); | ||
|
||
const debouncedAnimateResize = React.useMemo( | ||
() => debounce((key, entry) => animateResize(key, entry), Constants.DEBOUNCETIMEOUT), | ||
[animateResize] | ||
); | ||
|
||
React.useEffect(() => { | ||
const setAnimationState = setAnimationStateRef.current; | ||
const elementId = elementIdRef.current; | ||
setAnimationState((oldValue) => ({ | ||
...oldValue, | ||
[elementId]: null, | ||
})); | ||
return () => { | ||
setAnimationState((v) => { | ||
const {[elementId]: _, ...rest} = v; | ||
return rest; | ||
}); | ||
}; | ||
}, [elementIdRef]); | ||
|
||
useResizeObserver(elementRef, (entry) => | ||
debouncedAnimateResize(elementIdRef.current, entry) | ||
); | ||
|
||
|
||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.