UNPKG

@sendbird/uikit-react-native

Version:

Sendbird UIKit for React Native: A feature-rich and customizable chat UI kit with messaging, channel management, and user authentication.

66 lines 2.55 kB
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } import React, { forwardRef, useRef } from 'react'; import { StyleSheet } from 'react-native'; import { useUIKitTheme } from '@sendbird/uikit-react-native-foundation'; import { NOOP, getMessageUniqId, useFreshCallback } from '@sendbird/uikit-utils'; import FlatListInternal from '../ChatFlatList/FlatListInternal'; const BOTTOM_DETECT_THRESHOLD = 50; const UNREACHABLE_THRESHOLD = Number.MIN_SAFE_INTEGER; const ThreadChatFlatList = /*#__PURE__*/forwardRef(function ThreadChatFlatList(_ref, ref) { let { onTopReached, onBottomReached, onScrolledAwayFromBottom, onScroll, ...props } = _ref; const { select } = useUIKitTheme(); const contentOffsetY = useRef(0); const _onScroll = useFreshCallback(event => { onScroll === null || onScroll === void 0 ? void 0 : 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 /*#__PURE__*/React.createElement(FlatListInternal, _extends({ bounces: false, removeClippedSubviews: true, keyboardDismissMode: 'on-drag', keyboardShouldPersistTaps: 'handled', indicatorStyle: select({ light: 'black', dark: 'white' }) }, props, { ref: ref, onEndReached: onBottomReached, onScrollToIndexFailed: NOOP, onStartReached: onTopReached, scrollEventThrottle: 16, onScroll: _onScroll, keyExtractor: getMessageUniqId, style: { flex: 1, ...StyleSheet.flatten(props.style) }, maintainVisibleContentPosition: { minIndexForVisible: 0, autoscrollToTopThreshold: UNREACHABLE_THRESHOLD } })); }); export default ThreadChatFlatList; //# sourceMappingURL=index.js.map