import React from 'react'; import { FlatList, Pressable, View, useWindowDimensions } from 'react-native'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { Image, Modal, createStyleSheet, useUIKitTheme } from '@gathertown/uikit-react-native-foundation'; import { UNKNOWN_USER_ID } from '../../constants'; import type { ReactionBottomSheetProps } from './index'; const NUM_COLUMN = 6; const ReactionListBottomSheet = ({ visible, onClose, onDismiss, reactionCtx, chatCtx }: ReactionBottomSheetProps) => { const { width } = useWindowDimensions(); const { bottom, left, right } = useSafeAreaInsets(); const { colors } = useUIKitTheme(); const { currentUser, emojiManager } = chatCtx; const { channel, message } = reactionCtx; const color = colors.ui.reaction.default; return ( item.key} contentContainerStyle={styles.flatlist} ItemSeparatorComponent={() => } renderItem={({ item: { key, url } }) => { const reactedUserIds = message?.reactions?.find((it) => it.key === key)?.userIds ?? []; const idx = reactedUserIds.indexOf(currentUser?.userId ?? UNKNOWN_USER_ID); const reacted = idx > -1; return ( { if (message && channel) { if (reacted) channel.deleteReaction(message, key); else channel.addReaction(message, key); } onClose(); }} style={({ pressed }) => [ styles.button, { backgroundColor: reacted || pressed ? color.selected.background : color.enabled.background }, ]} > ); }} /> ); }; const styles = createStyleSheet({ container: { overflow: 'hidden', borderTopLeftRadius: 8, borderTopRightRadius: 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;