Files
AFFiNE-Mirror/packages/frontend/component/src/ui/scrollbar/use-has-scroll-top.tsx
T
pengx17 1efc1d0f5b feat(electron): multi tabs support (#7440)
use https://www.electronjs.org/docs/latest/api/web-contents-view to serve different tab views
added tabs view manager in electron to handle multi-view actions and events.

fix AF-1111
fix AF-999
fix PD-1459
fix AF-964
PD-1458
2024-07-29 11:05:22 +00:00

28 lines
821 B
TypeScript

import { debounce } from 'lodash-es';
import { useMemo, useState } from 'react';
export function useHasScrollTop() {
const [hasScrollTop, setHasScrollTop] = useState(false);
const containerRefFn = useMemo(() => {
let unsub: (() => void) | null = null;
return (container: HTMLElement | null) => {
unsub?.();
const updateScrollTop = debounce(() => {
if (container) {
setTimeout(() => {
const hasScrollTop = container.scrollTop > 0;
setHasScrollTop(hasScrollTop);
});
}
}, 50);
container?.addEventListener('scroll', updateScrollTop);
updateScrollTop();
unsub = () => {
container?.removeEventListener('scroll', updateScrollTop);
};
};
}, []);
return [containerRefFn, hasScrollTop] as const;
}