@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.
119 lines • 3.84 kB
JavaScript
import React from 'react';
import { Pressable, View } from 'react-native';
import { Icon, Image, createStyleSheet, useUIKitTheme } from '@sendbird/uikit-react-native-foundation';
import { useGroupChannelHandler } from '@sendbird/uikit-tools';
import { Logger, useSafeAreaPadding } from '@sendbird/uikit-utils';
import { UNKNOWN_USER_ID } from '../../constants';
import { useReaction, useSendbirdChat } from '../../hooks/useContext';
const BottomSheetReactionAddon = ({
onClose,
message,
channel
}) => {
const {
emojiManager,
currentUser,
sdk
} = useSendbirdChat();
const {
updateReactionFocusedItem,
openReactionList
} = useReaction();
const {
colors
} = useUIKitTheme();
const safeArea = useSafeAreaPadding(['left', 'right']);
useGroupChannelHandler(sdk, {
async onReactionUpdated(eventChannel, event) {
if ((channel === null || channel === void 0 ? void 0 : channel.url) === eventChannel.url && event.messageId === (message === null || message === void 0 ? void 0 : message.messageId)) {
const msg = await sdk.message.getMessage({
includeReactions: true,
messageId: message.messageId,
channelUrl: message.channelUrl,
channelType: message.channelType
});
if (msg) updateReactionFocusedItem({
message: msg
});
}
}
});
const emojiAll = emojiManager.allEmoji.slice(0, 5);
const color = colors.ui.reaction.default;
return /*#__PURE__*/React.createElement(View, {
style: [styles.container, {
marginStart: safeArea.paddingStart,
marginEnd: safeArea.paddingEnd
}]
}, emojiAll.map(({
key,
url
}) => {
var _message$reactions;
const reactionUserIds = (message === null || message === void 0 || (_message$reactions = message.reactions) === null || _message$reactions === void 0 || (_message$reactions = _message$reactions.find(it => it.key === key)) === null || _message$reactions === void 0 ? void 0 : _message$reactions.userIds) ?? [];
const currentUserIdx = reactionUserIds.indexOf((currentUser === null || currentUser === void 0 ? void 0 : currentUser.userId) ?? UNKNOWN_USER_ID);
const reacted = currentUserIdx > -1;
const onPress = async () => {
const action = (message, key) => {
return reacted ? channel.deleteReaction(message, key) : channel.addReaction(message, key);
};
await action(message, key).catch(error => {
Logger.warn('Failed to reaction', error);
}).finally(() => {
onClose();
});
};
return /*#__PURE__*/React.createElement(Pressable, {
key: key,
onPress: onPress,
style: ({
pressed
}) => [styles.button, {
backgroundColor: reacted || pressed ? color.selected.background : color.enabled.background
}]
}, /*#__PURE__*/React.createElement(Image, {
source: {
uri: url
},
style: styles.emoji
}));
}), /*#__PURE__*/React.createElement(Pressable, {
onPress: async () => {
await onClose();
openReactionList({
channel,
message
});
},
style: ({
pressed
}) => [styles.button, {
backgroundColor: pressed ? color.selected.background : color.enabled.background
}]
}, /*#__PURE__*/React.createElement(Icon, {
icon: 'emoji-more',
style: styles.emoji,
color: colors.onBackground03
})));
};
const styles = createStyleSheet({
container: {
paddingTop: 12,
paddingBottom: 16,
paddingHorizontal: 18,
flexDirection: 'row',
justifyContent: 'space-between'
},
button: {
width: 44,
height: 44,
padding: 4,
borderRadius: 8
},
emoji: {
width: '100%',
height: '100%'
}
});
export default BottomSheetReactionAddon;
//# sourceMappingURL=BottomSheetReactionAddon.js.map