Fix animation glitch
This commit is contained in:
@@ -9,20 +9,21 @@ export function useAnimationToIndicateTopicUpdate(
|
|||||||
) {
|
) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (ref.current && shouldAnimate && Date.now() - lastUpdate < 3000 && !selected) {
|
if (ref.current && shouldAnimate && Date.now() - lastUpdate < 3000 && !selected) {
|
||||||
|
let timeout: any
|
||||||
let animationFrame = requestAnimationFrame(() => {
|
let animationFrame = requestAnimationFrame(() => {
|
||||||
ref.current && ref.current.classList.add(className)
|
ref.current && ref.current.classList.add(className)
|
||||||
|
|
||||||
|
timeout = setTimeout(
|
||||||
|
() =>
|
||||||
|
(animationFrame = requestAnimationFrame(() => {
|
||||||
|
ref.current && ref.current.classList.remove(className)
|
||||||
|
})),
|
||||||
|
500
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
const timeout = setTimeout(
|
|
||||||
() =>
|
|
||||||
(animationFrame = requestAnimationFrame(() => {
|
|
||||||
ref.current && ref.current.classList.remove(className)
|
|
||||||
})),
|
|
||||||
500
|
|
||||||
)
|
|
||||||
|
|
||||||
return function cleanup() {
|
return function cleanup() {
|
||||||
clearTimeout(timeout)
|
timeout && clearTimeout(timeout)
|
||||||
animationFrame && cancelAnimationFrame(animationFrame)
|
animationFrame && cancelAnimationFrame(animationFrame)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user