200 lines
7.2 KiB
TypeScript
200 lines
7.2 KiB
TypeScript
// Metro module 10903 (f10904).
|
|
import { useRef } from "react";
|
|
import { updateIsAtBottom, updateShouldShowJumpToPresentButton } from "../../../chat_input/native/useChatBottomManagerUIStore";
|
|
import Logger from "../../../debug/Logger";
|
|
import { getIsScreenReaderEnabled } from "../../../a11y/native/useIsScreenReaderEnabled.native";
|
|
import DimensionActionCreators from "../../../../actions/DimensionActionCreators";
|
|
import { batchUpdates } from "../../../../_bundle/Module705";
|
|
import NativeChatUtils from "../../../chat/native/NativeChatUtils";
|
|
import { getChangesetIdForChat } from "../../../chat/native/ChatChangesetUpdateTracker";
|
|
import { QuestsVisibleMessagesChangedSource } from "../../../quests/QuestTypes";
|
|
let c7341_6 = new Logger("useScrollHandlers");
|
|
export default function useScrollHandlers({ chatRef, chatManager, chatUpdatesQueue, pendingUpdatesQueueRef, animatedRef, fetchMoreBefore, fetchMoreAfter, handleVisibleMessagesChange, applyNativeRowsUpdate, messages, channel, channelId, screenIndex, onScroll, useReducedMotion, isStaff, visibleMessagesWindowHandler }) {
|
|
let ref, ref2, ref3, ref4, ref5, ref6, ref7, handleScroll2;
|
|
ref = void 0;
|
|
ref2 = void 0;
|
|
ref3 = void 0;
|
|
ref4 = void 0;
|
|
ref5 = void 0;
|
|
ref6 = void 0;
|
|
ref7 = void 0;
|
|
const handleScrollCallbacks2 = function handleScrollCallbacks(a0) {
|
|
const { eventTimestamp, isAtBottom: isAtBottom2, isNearBottom = false, isNearTop = false } = a0;
|
|
let dragging = a0.dragging;
|
|
if (dragging === void 0) {
|
|
dragging = false;
|
|
}
|
|
const { decelerating = false, isFirstMessageVisible = false } = a0;
|
|
L38: {
|
|
if (channel != null) {
|
|
if (messages.length === 0 && messages.loadingMore) {
|
|
break L38;
|
|
}
|
|
const isScreenReaderEnabled = getIsScreenReaderEnabled();
|
|
const loadingMore = messages.loadingMore;
|
|
let r32 = !loadingMore;
|
|
if (!loadingMore) {
|
|
if (!dragging) {
|
|
dragging = decelerating;
|
|
}
|
|
if (!dragging) {
|
|
dragging = isScreenReaderEnabled;
|
|
}
|
|
r32 = dragging;
|
|
}
|
|
if (r32) {
|
|
r32 = pendingUpdatesQueueRef.current.length === 0;
|
|
}
|
|
if (!ref5.current && (isNearTop && (messages.hasMoreBefore && r32))) {
|
|
animatedRef.current = true;
|
|
fetchMoreBefore();
|
|
} else if (!ref4.current && (isNearBottom && (messages.hasMoreAfter && r32))) {
|
|
animatedRef.current = true;
|
|
fetchMoreAfter();
|
|
} else if (!(ref3.current === isAtBottom2 && ref2.current)) {
|
|
DimensionActionCreators.updateChannelDimensions(channel.id, eventTimestamp, isAtBottom2 ? 1 : 0, 1, 0);
|
|
ref2.current = true;
|
|
}
|
|
onScroll({
|
|
isFirstMessageVisible
|
|
});
|
|
chatUpdatesQueue.tryFlush();
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
handleScroll2 = function handleScroll(a0) {
|
|
const { eventTimestamp, isAtBottom, isNearBottom = false, isNearTop = false, dragging = false, decelerating = false, shouldShowJumpToPresent = false } = a0;
|
|
let c26846_1 = shouldShowJumpToPresent;
|
|
let isFirstMessageVisible = a0.isFirstMessageVisible;
|
|
if (isFirstMessageVisible === void 0) {
|
|
isFirstMessageVisible = false;
|
|
}
|
|
if (handleScrollCallbacks2({
|
|
eventTimestamp,
|
|
isAtBottom,
|
|
isNearBottom,
|
|
isNearTop,
|
|
dragging,
|
|
decelerating,
|
|
shouldShowJumpToPresent,
|
|
isFirstMessageVisible
|
|
})) {
|
|
ref3.current = isAtBottom;
|
|
ref4.current = isNearBottom;
|
|
ref5.current = isNearTop;
|
|
ref7.current = dragging;
|
|
ref6.current = decelerating;
|
|
batchUpdates(() => {
|
|
updateShouldShowJumpToPresentButton(channelId, screenIndex, c26846_1 || messages.hasMoreAfter);
|
|
updateIsAtBottom(screenIndex, isAtBottom);
|
|
});
|
|
}
|
|
};
|
|
ref = useRef(void 0);
|
|
ref2 = useRef(false);
|
|
ref3 = useRef(false);
|
|
ref4 = useRef(false);
|
|
ref5 = useRef(false);
|
|
ref6 = useRef(false);
|
|
ref7 = useRef(false);
|
|
return {
|
|
hasHandledScrollRef: ref2,
|
|
isAtBottomRef: ref3,
|
|
isNearBottomRef: ref4,
|
|
isNearTopRef: ref5,
|
|
deceleratingRef: ref6,
|
|
draggingRef: ref7,
|
|
firstIgnoredScrollEventTimestampRef: ref,
|
|
loadMoreBefore: function loadMoreBefore() {
|
|
animatedRef.current = true;
|
|
fetchMoreBefore();
|
|
},
|
|
loadMoreAfter: function loadMoreAfter() {
|
|
animatedRef.current = true;
|
|
fetchMoreAfter();
|
|
},
|
|
scrollToTop: function scrollToTop(r5 = true) {
|
|
const current = chatRef.current;
|
|
if (r5) {
|
|
r5 = !useReducedMotion;
|
|
}
|
|
NativeChatUtils.scrollToTop(current, r5);
|
|
},
|
|
scrollToRelativeOffset: function scrollToRelativeOffset(a0, r6 = true) {
|
|
const current = chatRef.current;
|
|
if (r6) {
|
|
r6 = !useReducedMotion;
|
|
}
|
|
NativeChatUtils.scrollToRelativeOffset(current, a0, r6);
|
|
},
|
|
scrollToTopMessage: function scrollToTopMessage() {
|
|
const previousRows = chatManager.getPreviousRows();
|
|
if (previousRows.length > 0) {
|
|
NativeChatUtils.scrollTo(chatRef.current, previousRows.length - 1);
|
|
}
|
|
},
|
|
updateNativeRows: function updateNativeRows(a0) {
|
|
L7: {
|
|
if (chatUpdatesQueue.isBlocking) {
|
|
chatUpdatesQueue.add(a0);
|
|
} else {
|
|
L4: {
|
|
if (a0.isLoadingAtTop) {
|
|
if (!ref6.current && !ref7.current) {
|
|
break L4;
|
|
}
|
|
chatUpdatesQueue.add(a0);
|
|
break L7;
|
|
}
|
|
}
|
|
applyNativeRowsUpdate(a0);
|
|
}
|
|
}
|
|
},
|
|
handleScrollCallbacks: handleScrollCallbacks2,
|
|
handleScroll: handleScroll2,
|
|
handleScrollPosition: function handleScrollPosition({ timeStamp, nativeEvent }) {
|
|
const { isAtBottom: isAtBottom2, isNearBottom, isNearTop, dragging, decelerating, shouldShowJumpToPresent, isFirstMessageVisible, firstVisibleMessageIndex, firstVisibleMessagePercentVisible, lastVisibleMessageIndex, changesetUpdateId, lastVisibleMessagePercentVisible } = nativeEvent;
|
|
const changesetIdForChat = getChangesetIdForChat(chatRef.current);
|
|
if (changesetUpdateId !== changesetIdForChat) {
|
|
if (ref.current == null) {
|
|
ref.current = timeStamp;
|
|
}
|
|
if (isStaff) {
|
|
c7341_6.log("STAFF-ACK-LOG: Ignoring outdated scroll event.", channelId, changesetUpdateId, changesetIdForChat, timeStamp);
|
|
}
|
|
return void 0;
|
|
}
|
|
handleVisibleMessagesChange({
|
|
firstVisibleMessageRowIndex: firstVisibleMessageIndex,
|
|
lastVisibleMessageRowIndex: lastVisibleMessageIndex,
|
|
firstVisibleMessagePercentVisible,
|
|
lastVisibleMessagePercentVisible,
|
|
source: QuestsVisibleMessagesChangedSource.SCROLL
|
|
});
|
|
let current = ref.current;
|
|
if (current == null) {
|
|
current = timeStamp;
|
|
}
|
|
ref.current = void 0;
|
|
handleScroll2({
|
|
eventTimestamp: current,
|
|
isAtBottom: isAtBottom2,
|
|
isNearBottom,
|
|
isNearTop,
|
|
dragging,
|
|
decelerating,
|
|
shouldShowJumpToPresent,
|
|
isFirstMessageVisible
|
|
});
|
|
visibleMessagesWindowHandler.handleScrollPosition({
|
|
rows: chatManager._rows,
|
|
firstVisibleMessageRowIndex: firstVisibleMessageIndex,
|
|
lastVisibleMessageRowIndex: lastVisibleMessageIndex
|
|
});
|
|
}
|
|
};
|
|
};
|