UNPKG

stream-chat-react-native-core

Version:

The official React Native and Expo components for Stream Chat, a service for building chat applications

172 lines 8.03 kB
Object.defineProperty(exports, "__esModule", { value: true }); exports.ReactionListClusteredWithContext = exports.ReactionListClustered = void 0; var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _ReactionListItemWrapper = require("./ReactionListItemWrapper"); var _useA11yLabel = require("../../../../a11y/hooks/useA11yLabel"); var _ComponentsContext = require("../../../../contexts/componentsContext/ComponentsContext"); var _MessageContext = require("../../../../contexts/messageContext/MessageContext"); var _MessagesContext = require("../../../../contexts/messagesContext/MessagesContext"); var _ThemeContext = require("../../../../contexts/themeContext/ThemeContext"); var _theme = require("../../../../theme"); var _HiddenA11yText = require("../../../Accessibility/HiddenA11yText"); var _jsxRuntime = require("react/jsx-runtime"); var _jsxFileName = "/home/runner/work/stream-chat-react-native/stream-chat-react-native/package/src/components/Message/MessageItemView/ReactionList/ReactionListClustered.tsx"; function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); } var Icon = ({ size, style, supportedReactions, type }) => { var _supportedReactions$f; var _useComponentsContext = (0, _ComponentsContext.useComponentsContext)(), icons = _useComponentsContext.icons; var ReactionIcon = (supportedReactions == null || (_supportedReactions$f = supportedReactions.find(reaction => reaction.type === type)) == null ? void 0 : _supportedReactions$f.Icon) || icons.Unknown; return (0, _jsxRuntime.jsx)(ReactionIcon, { size: size, style: style }); }; var ReactionListClusteredWithContext = props => { var hasReactions = props.hasReactions, onPress = props.onPress, onPressIn = props.onPressIn, preventPress = props.preventPress, reactions = props.reactions, showReactionsOverlay = props.showReactionsOverlay, supportedReactions = props.supportedReactions, containerStyle = props.containerStyle, accessibilityLabel = props.accessibilityLabel; var _useTheme = (0, _ThemeContext.useTheme)(), icon = _useTheme.theme.messageItemView.reactionListClustered.icon; var styles = useStyles(); var accessibilityHint = (0, _useA11yLabel.useA11yLabel)('a11y/Double tap to view reactions'); var youReacted = (0, _useA11yLabel.useA11yLabel)('a11y/you reacted'); var supportedReactionTypes = supportedReactions == null ? void 0 : supportedReactions.map(supportedReaction => supportedReaction.type); var reactionsCount = (reactions == null ? void 0 : reactions.length) || 0; var moreReactionsCount = reactionsCount - 4; var reactionsCountText = moreReactionsCount < 99 ? moreReactionsCount : `+${moreReactionsCount}`; var moreReactionsA11yText = (0, _useA11yLabel.useA11yLabel)('a11y/and {{count}} more reactions', { count: moreReactionsCount }); var hasSupportedReactions = reactions == null ? void 0 : reactions.some(reaction => supportedReactionTypes == null ? void 0 : supportedReactionTypes.includes(reaction.type)); if (!hasSupportedReactions || !hasReactions) { return null; } return (0, _jsxRuntime.jsxs)(_ReactionListItemWrapper.ReactionListItemWrapper, { accessibilityHint: accessibilityHint, accessibilityLabel: accessibilityLabel, disabled: preventPress, onPress: event => { if (onPress) { onPress({ defaultHandler: () => { if (showReactionsOverlay) { showReactionsOverlay(undefined); } }, emitter: 'reactionList', event }); } }, onPressIn: event => { if (onPressIn) { onPressIn({ defaultHandler: () => { if (showReactionsOverlay) { showReactionsOverlay(undefined); } }, emitter: 'reactionList', event }); } }, style: containerStyle, children: [reactions == null ? void 0 : reactions.slice(0, 4).map(reaction => (0, _jsxRuntime.jsxs)(_react.Fragment, { children: [(0, _jsxRuntime.jsx)(Icon, { size: icon.size, style: [styles.iconStyle, icon.style], supportedReactions: supportedReactions, type: reaction.type }), reaction.own ? (0, _jsxRuntime.jsx)(_HiddenA11yText.HiddenA11yText, { label: youReacted }) : null] }, reaction.type)), reactionsCount > 4 ? (0, _jsxRuntime.jsx)(_reactNative.Text, { accessibilityLabel: moreReactionsA11yText, style: styles.reactionCount, children: reactionsCountText }) : null] }); }; exports.ReactionListClusteredWithContext = ReactionListClusteredWithContext; var areEqual = (prevProps, nextProps) => { var prevHasReactions = prevProps.hasReactions, prevReactions = prevProps.reactions; var nextHasReactions = nextProps.hasReactions, nextReactions = nextProps.reactions; var hasReactionsEqual = prevHasReactions === nextHasReactions; if (!hasReactionsEqual) { return false; } var reactionsEqual = (prevReactions == null ? void 0 : prevReactions.length) === (nextReactions == null ? void 0 : nextReactions.length) && (prevReactions || []).every((reaction, index) => { var nextReaction = nextReactions == null ? void 0 : nextReactions[index]; return reaction.type === (nextReaction == null ? void 0 : nextReaction.type) && reaction.count === (nextReaction == null ? void 0 : nextReaction.count) && reaction.own === (nextReaction == null ? void 0 : nextReaction.own); }); if (!reactionsEqual) { return false; } return true; }; var MemoizedReactionListClustered = _react.default.memo(ReactionListClusteredWithContext, areEqual); var ReactionListClustered = props => { var _useMessageContext = (0, _MessageContext.useMessageContext)(), hasReactions = _useMessageContext.hasReactions, onPress = _useMessageContext.onPress, onPressIn = _useMessageContext.onPressIn, preventPress = _useMessageContext.preventPress, reactions = _useMessageContext.reactions, showReactionsOverlay = _useMessageContext.showReactionsOverlay; var _useMessagesContext = (0, _MessagesContext.useMessagesContext)(), supportedReactions = _useMessagesContext.supportedReactions; return (0, _jsxRuntime.jsx)(MemoizedReactionListClustered, { hasReactions, onPress, onPressIn, preventPress, reactions, showReactionsOverlay, supportedReactions, ...props }); }; exports.ReactionListClustered = ReactionListClustered; var useStyles = () => { var _useTheme2 = (0, _ThemeContext.useTheme)(), _useTheme2$theme = _useTheme2.theme, semantics = _useTheme2$theme.semantics, _useTheme2$theme$mess = _useTheme2$theme.messageItemView.reactionListClustered, contentContainer = _useTheme2$theme$mess.contentContainer, reactionCount = _useTheme2$theme$mess.reactionCount, iconStyle = _useTheme2$theme$mess.iconStyle; return (0, _react.useMemo)(() => _reactNative.StyleSheet.create({ contentContainer: { ...contentContainer }, reactionCount: { color: semantics.reactionText, fontSize: _theme.primitives.typographyFontSizeXxs, fontWeight: _theme.primitives.typographyFontWeightBold, lineHeight: _theme.primitives.typographyLineHeightTight, ...reactionCount }, iconStyle: { ...iconStyle } }), [semantics, reactionCount, iconStyle, contentContainer]); }; //# sourceMappingURL=ReactionListClustered.js.map