Follow-up
This commit is contained in:
parent
0e8b0df843
commit
7d1b9a7f18
@ -83,7 +83,7 @@ export default function useScrollHooks(
|
||||
});
|
||||
|
||||
const {
|
||||
observe: observeIntersection,
|
||||
observe: observeIntersectionForHistory,
|
||||
} = useIntersectionObserver({
|
||||
rootRef: containerRef,
|
||||
margin: MESSAGE_LIST_SENSITIVE_AREA,
|
||||
@ -98,24 +98,23 @@ export default function useScrollHooks(
|
||||
return;
|
||||
}
|
||||
|
||||
const triggerEntry = entries.find(({ isIntersecting }) => isIntersecting);
|
||||
if (!triggerEntry) {
|
||||
return;
|
||||
}
|
||||
entries.forEach(({ isIntersecting, target }) => {
|
||||
if (!isIntersecting) return;
|
||||
|
||||
const { target } = triggerEntry;
|
||||
if (target.className === 'backwards-trigger') {
|
||||
loadMoreBackwards();
|
||||
}
|
||||
|
||||
if (target.className === 'backwards-trigger') {
|
||||
loadMoreBackwards();
|
||||
} else if (target.className === 'forwards-trigger') {
|
||||
loadMoreForwards();
|
||||
}
|
||||
if (target.className === 'forwards-trigger') {
|
||||
loadMoreForwards();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const withHistoryTriggers = messageIds && messageIds.length > 1;
|
||||
|
||||
useOnIntersect(backwardsTriggerRef, withHistoryTriggers ? observeIntersection : undefined);
|
||||
useOnIntersect(forwardsTriggerRef, withHistoryTriggers ? observeIntersection : undefined);
|
||||
useOnIntersect(backwardsTriggerRef, withHistoryTriggers ? observeIntersectionForHistory : undefined);
|
||||
useOnIntersect(forwardsTriggerRef, withHistoryTriggers ? observeIntersectionForHistory : undefined);
|
||||
|
||||
const {
|
||||
observe: observeIntersectionForFab,
|
||||
|
||||
@ -6,7 +6,6 @@ import type { Scheduler } from '../util/schedulers';
|
||||
import {
|
||||
throttle, debounce, throttleWith,
|
||||
} from '../util/schedulers';
|
||||
import useEffectOnce from './useEffectOnce';
|
||||
import useHeavyAnimationCheck from './useHeavyAnimationCheck';
|
||||
import useLastCallback from './useLastCallback';
|
||||
|
||||
@ -171,10 +170,9 @@ export function useIntersectionObserver({
|
||||
export function useOnIntersect(
|
||||
targetRef: RefObject<HTMLDivElement>, observe?: ObserveFn, callback?: TargetCallback,
|
||||
) {
|
||||
useEffectOnce(() => {
|
||||
useEffect(() => {
|
||||
return observe ? observe(targetRef.current!, callback) : undefined;
|
||||
// Arguments should never change
|
||||
});
|
||||
}, [callback, observe, targetRef]);
|
||||
}
|
||||
|
||||
export function useIsIntersecting(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user