mirror of
https://github.com/danog/telegram-tt.git
synced 2024-12-13 09:37:29 +01:00
Intersection Observer: Make sure to always unfreeze
This commit is contained in:
parent
a185fd9407
commit
97453fec52
@ -22,6 +22,8 @@ interface Response {
|
|||||||
unfreeze: NoneToVoidFunction;
|
unfreeze: NoneToVoidFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const AUTO_UNFREEZE_TIMEOUT = 2000;
|
||||||
|
|
||||||
export function useIntersectionObserver({
|
export function useIntersectionObserver({
|
||||||
rootRef,
|
rootRef,
|
||||||
throttleMs,
|
throttleMs,
|
||||||
@ -42,14 +44,11 @@ export function useIntersectionObserver({
|
|||||||
const controllerRef = useRef<IntersectionController>();
|
const controllerRef = useRef<IntersectionController>();
|
||||||
const rootCallbackRef = useRef<RootCallback>();
|
const rootCallbackRef = useRef<RootCallback>();
|
||||||
const freezeFlagsRef = useRef(0);
|
const freezeFlagsRef = useRef(0);
|
||||||
|
const autoUnfreezeTimeoutRef = useRef<number>();
|
||||||
const onUnfreezeRef = useRef<NoneToVoidFunction>();
|
const onUnfreezeRef = useRef<NoneToVoidFunction>();
|
||||||
|
|
||||||
rootCallbackRef.current = rootCallback;
|
rootCallbackRef.current = rootCallback;
|
||||||
|
|
||||||
const freeze = useCallback(() => {
|
|
||||||
freezeFlagsRef.current++;
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const unfreeze = useCallback(() => {
|
const unfreeze = useCallback(() => {
|
||||||
if (!freezeFlagsRef.current) {
|
if (!freezeFlagsRef.current) {
|
||||||
return;
|
return;
|
||||||
@ -63,6 +62,27 @@ export function useIntersectionObserver({
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const freeze = useCallback(() => {
|
||||||
|
freezeFlagsRef.current++;
|
||||||
|
|
||||||
|
if (autoUnfreezeTimeoutRef.current) {
|
||||||
|
clearTimeout(autoUnfreezeTimeoutRef.current);
|
||||||
|
autoUnfreezeTimeoutRef.current = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure to unfreeze even if unfreeze callback was not called (which was some hardly-reproducible bug)
|
||||||
|
autoUnfreezeTimeoutRef.current = window.setTimeout(() => {
|
||||||
|
autoUnfreezeTimeoutRef.current = undefined;
|
||||||
|
|
||||||
|
if (!freezeFlagsRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
freezeFlagsRef.current = 1;
|
||||||
|
unfreeze();
|
||||||
|
}, AUTO_UNFREEZE_TIMEOUT);
|
||||||
|
}, [unfreeze]);
|
||||||
|
|
||||||
useHeavyAnimationCheck(freeze, unfreeze);
|
useHeavyAnimationCheck(freeze, unfreeze);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
Loading…
Reference in New Issue
Block a user