import React, { forwardRef, useRef } from 'react'; import { FlatListProps, FlatList as RNFlatList, StyleSheet } from 'react-native'; import { useUIKitTheme } from '@sendbird/uikit-react-native-foundation'; import { NOOP, SendbirdMessage, getMessageUniqId, useFreshCallback } from '@sendbird/uikit-utils'; import FlatListInternal from '../ChatFlatList/FlatListInternal'; const BOTTOM_DETECT_THRESHOLD = 50; const UNREACHABLE_THRESHOLD = Number.MIN_SAFE_INTEGER; type Props = Omit, 'onEndReached'> & { onBottomReached: () => void; onTopReached: () => void; onScrolledAwayFromBottom: (value: boolean) => void; }; const ThreadChatFlatList = forwardRef(function ThreadChatFlatList( { onTopReached, onBottomReached, onScrolledAwayFromBottom, onScroll, ...props }, ref, ) { const { select } = useUIKitTheme(); const contentOffsetY = useRef(0); const _onScroll = useFreshCallback>((event) => { onScroll?.(event); const { contentOffset, contentSize, layoutMeasurement } = event.nativeEvent; const prevOffsetY = contentOffsetY.current; const currOffsetY = contentOffset.y; const bottomDetectThreshold = contentSize.height - layoutMeasurement.height - BOTTOM_DETECT_THRESHOLD; if (bottomDetectThreshold < prevOffsetY && currOffsetY <= bottomDetectThreshold) { onScrolledAwayFromBottom(true); } else if (bottomDetectThreshold < currOffsetY && prevOffsetY <= bottomDetectThreshold) { onScrolledAwayFromBottom(false); } contentOffsetY.current = contentOffset.y; }); return ( ); }); export default ThreadChatFlatList;