@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.
127 lines • 3.85 kB
JavaScript
import React from 'react';
import { FlatList, Pressable, View, useWindowDimensions } from 'react-native';
import { Image, Modal, createStyleSheet, useUIKitTheme } from '@sendbird/uikit-react-native-foundation';
import { Logger, useSafeAreaPadding } from '@sendbird/uikit-utils';
import { UNKNOWN_USER_ID } from '../../constants';
const NUM_COLUMN = 6;
const ReactionListBottomSheet = ({
visible,
onClose,
onDismiss,
reactionCtx,
chatCtx
}) => {
const {
width
} = useWindowDimensions();
const safeArea = useSafeAreaPadding(['bottom', 'left', 'right']);
const {
colors
} = useUIKitTheme();
const {
currentUser,
emojiManager
} = chatCtx;
const {
channel,
message
} = reactionCtx;
const color = colors.ui.reaction.default;
return /*#__PURE__*/React.createElement(Modal, {
type: 'slide',
visible: Boolean(visible && channel && message),
onClose: onClose,
onDismiss: onDismiss,
backgroundStyle: styles.modal
}, /*#__PURE__*/React.createElement(View, {
style: [styles.container, {
width,
paddingBottom: safeArea.paddingBottom,
backgroundColor: colors.ui.dialog.default.none.background,
paddingStart: safeArea.paddingStart + styles.container.paddingHorizontal,
paddingEnd: safeArea.paddingEnd + styles.container.paddingHorizontal
}]
}, /*#__PURE__*/React.createElement(FlatList, {
data: emojiManager.allEmoji,
numColumns: NUM_COLUMN,
keyExtractor: item => item.key,
contentContainerStyle: styles.flatlist,
ItemSeparatorComponent: () => /*#__PURE__*/React.createElement(View, {
style: {
height: 16
}
}),
renderItem: ({
item: {
key,
url
}
}) => {
var _message$reactions;
const reactedUserIds = (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 idx = reactedUserIds.indexOf((currentUser === null || currentUser === void 0 ? void 0 : currentUser.userId) ?? UNKNOWN_USER_ID);
const reacted = idx > -1;
return /*#__PURE__*/React.createElement(View, {
style: styles.emojiItem
}, /*#__PURE__*/React.createElement(Pressable, {
key: key,
onPress: async () => {
if (message && channel) {
const action = (message, key) => {
return reacted ? channel.deleteReaction(message, key) : channel.addReaction(message, key);
};
action(message, key).catch(error => {
Logger.warn('Failed to reaction', error);
});
}
await onClose();
},
style: ({
pressed
}) => [styles.button, {
backgroundColor: reacted || pressed ? color.selected.background : color.enabled.background
}]
}, /*#__PURE__*/React.createElement(Image, {
source: {
uri: url
},
style: styles.emoji
})));
}
})));
};
const styles = createStyleSheet({
container: {
overflow: 'hidden',
borderTopStartRadius: 8,
borderTopEndRadius: 8,
paddingTop: 16,
paddingHorizontal: 18,
flexDirection: 'row'
},
modal: {
alignItems: 'center',
justifyContent: 'flex-end'
},
flatlist: {
width: '100%',
flexDirection: 'column',
justifyContent: 'space-between'
},
emojiItem: {
width: `${100 / NUM_COLUMN}%`,
alignItems: 'center'
},
button: {
width: 44,
height: 44,
padding: 4,
borderRadius: 8
},
emoji: {
width: '100%',
height: '100%'
}
});
export default ReactionListBottomSheet;
//# sourceMappingURL=ReactionListBottomSheet.js.map