@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.
65 lines • 2.45 kB
JavaScript
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, 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({
onTopReached,
onBottomReached,
onScrolledAwayFromBottom,
onScroll,
...props
}, ref) {
const {
select
} = useUIKitTheme();
const contentOffsetY = useRef(0);
const _onScroll = useFreshCallback(event => {
onScroll === null || onScroll === 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