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.

54 lines 2.03 kB
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, { useContext, useEffect, useRef, useState } from 'react'; import { useFreshCallback } from '@sendbird/uikit-utils'; import ChannelMessageList from '../../../components/ChannelMessageList'; import { OpenChannelContexts } from '../module/moduleContext'; const OpenChannelMessageList = props => { const { setMessageToEdit } = useContext(OpenChannelContexts.Fragment); const { subscribe } = useContext(OpenChannelContexts.PubSub); const ref = useRef(null); const [scrolledAwayFromBottom, setScrolledAwayFromBottom] = useState(false); const scrollToBottom = useFreshCallback((animated = false) => { // FIXME: Workaround, should run after data has been applied to UI. setTimeout(() => { var _ref$current; (_ref$current = ref.current) === null || _ref$current === void 0 || _ref$current.scrollToOffset({ offset: 0, animated }); }, 0); }); useEffect(() => { return subscribe(({ type }) => { switch (type) { case 'MESSAGES_RECEIVED': { scrollToBottom(false); break; } case 'MESSAGE_SENT_SUCCESS': case 'MESSAGE_SENT_PENDING': { scrollToBottom(false); break; } } }); }, []); return /*#__PURE__*/React.createElement(ChannelMessageList, _extends({}, props, { ref: ref, onPressScrollToBottomButton: scrollToBottom, onPressNewMessagesButton: scrollToBottom, scrolledAwayFromBottom: scrolledAwayFromBottom, onScrolledAwayFromBottom: setScrolledAwayFromBottom, onEditMessage: setMessageToEdit })); }; export default /*#__PURE__*/React.memo(OpenChannelMessageList); //# sourceMappingURL=OpenChannelMessageList.js.map