100 lines
3.5 KiB
JavaScript
100 lines
3.5 KiB
JavaScript
// Metro module 5464 (f5465).
|
|
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
import { useUnmountAwareAnimationFrame } from "./Module5461";
|
|
export function useBoundDetection(a0, a1) {
|
|
let callback;
|
|
const ref = useRef(false);
|
|
const ref2 = useRef(false);
|
|
const ref3 = useRef(false);
|
|
const ref4 = useRef(Date.now());
|
|
const data = a0.props.data;
|
|
const requestAnimationFrame2 = useUnmountAwareAnimationFrame().requestAnimationFrame;
|
|
const r11 = a0.hasLayout() ? a0.getWindowSize().height : 0;
|
|
const r9 = a0.hasLayout() ? a0.getChildContainerDimensions().height : 0;
|
|
const r38 = a0.hasLayout() ? a0.getWindowSize().width : 0;
|
|
const r43 = a0.hasLayout() ? a0.getChildContainerDimensions().width : 0;
|
|
const callback2 = useCallback(() => {
|
|
ref4.current = Date.now();
|
|
const props = a0.props;
|
|
const { onEndReached, onStartReached, maintainVisibleContentPosition, horizontal } = props;
|
|
let onEndReachedThreshold = props.onEndReachedThreshold;
|
|
let onStartReachedThreshold = props.onStartReachedThreshold;
|
|
let r26 = maintainVisibleContentPosition?.autoscrollToBottomThreshold;
|
|
if (r26 == null) {
|
|
r26 = -1;
|
|
}
|
|
if (!(!onEndReached && (!onStartReached && r26 < 0)) && a0.getIsFirstLayoutComplete()) {
|
|
const absoluteLastScrollOffset = a0.getAbsoluteLastScrollOffset();
|
|
const childContainerDimensions = a0.getChildContainerDimensions();
|
|
const windowSize = a0.getWindowSize();
|
|
const r33 = horizontal === true;
|
|
const r34 = r33 ? windowSize.width : windowSize.height;
|
|
const r37 = (r33 ? childContainerDimensions.width : childContainerDimensions.height) + a0.firstItemOffset;
|
|
if (r34 <= 0) {
|
|
return void 0;
|
|
}
|
|
if (onEndReached) {
|
|
if (onEndReachedThreshold == null) {
|
|
onEndReachedThreshold = 0.5;
|
|
}
|
|
const r39 = onEndReachedThreshold * r34;
|
|
const current = Math.ceil(absoluteLastScrollOffset + r34) >= r37 - r39;
|
|
if (current && !ref.current) {
|
|
ref.current = true;
|
|
onEndReached();
|
|
}
|
|
ref.current = current;
|
|
}
|
|
if (onStartReached) {
|
|
if (onStartReachedThreshold == null) {
|
|
onStartReachedThreshold = 0.2;
|
|
}
|
|
const current2 = absoluteLastScrollOffset <= onStartReachedThreshold * r34;
|
|
if (current2 && !ref2.current) {
|
|
ref2.current = true;
|
|
onStartReached();
|
|
}
|
|
ref2.current = current2;
|
|
}
|
|
if (!r33 && r26 >= 0) {
|
|
const r57 = r26 * r34;
|
|
ref3.current = !!(Math.ceil(absoluteLastScrollOffset + r34) >= r37 - r57);
|
|
}
|
|
}
|
|
}, [a0]);
|
|
callback = useCallback(() => {
|
|
if (a0.isOffsetProjectionEnabled && ref3.current) {
|
|
ref3.current = false;
|
|
requestAnimationFrame2(() => {
|
|
let animated = a0.props.maintainVisibleContentPosition?.animateAutoScrollToBottom;
|
|
if (animated == null) {
|
|
animated = true;
|
|
}
|
|
const current = a1.current;
|
|
if (current != null) {
|
|
if (animated) {
|
|
animated = !a0.ignoreScrollEvents;
|
|
}
|
|
current.scrollToEnd({
|
|
animated
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}, [requestAnimationFrame2, a1, a0]);
|
|
useMemo(() => {
|
|
ref.current = false;
|
|
}, [data]);
|
|
useEffect(() => {
|
|
callback();
|
|
}, [data, callback, r11, r38]);
|
|
useEffect(() => {
|
|
if (Date.now() - ref4.current >= 100) {
|
|
callback();
|
|
}
|
|
}, [r9, r43, a0.firstItemOffset, callback]);
|
|
return {
|
|
checkBounds: callback2
|
|
};
|
|
}
|