From 55a40c2436b68dea850e54a65c5dd197132c08e4 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Fri, 28 Mar 2025 08:43:40 +0200 Subject: [DMs] Emoji reaction picker (#8023) --- src/components/dms/EmojiReactionPicker.tsx | 118 +++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 src/components/dms/EmojiReactionPicker.tsx (limited to 'src/components/dms/EmojiReactionPicker.tsx') diff --git a/src/components/dms/EmojiReactionPicker.tsx b/src/components/dms/EmojiReactionPicker.tsx new file mode 100644 index 000000000..a98cebf9a --- /dev/null +++ b/src/components/dms/EmojiReactionPicker.tsx @@ -0,0 +1,118 @@ +import {useMemo, useState} from 'react' +import {Alert, useWindowDimensions, View} from 'react-native' +import {type ChatBskyConvoDefs} from '@atproto/api' +import {msg} from '@lingui/macro' +import {useLingui} from '@lingui/react' + +import {useSession} from '#/state/session' +import {atoms as a, tokens, useTheme} from '#/alf' +import * as ContextMenu from '#/components/ContextMenu' +import { + useContextMenuContext, + useContextMenuMenuContext, +} from '#/components/ContextMenu/context' +import { + EmojiHeartEyes_Stroke2_Corner0_Rounded as EmojiHeartEyesIcon, + EmojiSmile_Stroke2_Corner0_Rounded as EmojiSmileIcon, +} from '#/components/icons/Emoji' +import {type TriggerProps} from '#/components/Menu/types' +import {Text} from '#/components/Typography' +import {EmojiPopup} from './EmojiPopup' + +export function EmojiReactionPicker({ + message, +}: { + message: ChatBskyConvoDefs.MessageView + children?: TriggerProps['children'] +}) { + const {_} = useLingui() + const {currentAccount} = useSession() + const t = useTheme() + const isFromSelf = message.sender?.did === currentAccount?.did + const {measurement, close} = useContextMenuContext() + const {align} = useContextMenuMenuContext() + const [layout, setLayout] = useState({width: 0, height: 0}) + const {width: screenWidth} = useWindowDimensions() + + // 1 in 100 chance of showing heart eyes icon + const EmojiIcon = useMemo(() => { + return Math.random() < 0.01 ? EmojiHeartEyesIcon : EmojiSmileIcon + }, []) + + const handleEmojiSelect = (emoji: string) => { + Alert.alert(emoji) + } + + const position = useMemo(() => { + return { + x: align === 'left' ? 12 : screenWidth - layout.width - 12, + y: (measurement?.y ?? 0) - tokens.space.xs - layout.height, + height: layout.height, + width: layout.width, + } + }, [measurement, align, screenWidth, layout]) + + return ( + setLayout(evt.nativeEvent.layout)} + style={[ + a.rounded_full, + a.absolute, + {bottom: '100%'}, + isFromSelf ? a.right_0 : a.left_0, + t.scheme === 'light' ? t.atoms.bg : t.atoms.bg_contrast_25, + a.flex_row, + a.p_xs, + a.gap_xs, + a.mb_xs, + a.z_20, + a.border, + t.atoms.border_contrast_low, + a.shadow_md, + ]}> + {['👍', '😆', '❤️', '👀', '😢'].map(emoji => ( + handleEmojiSelect(emoji)} + unstyled> + {hovered => ( + + + {emoji} + + + )} + + ))} + { + close() + handleEmojiSelect(emoji) + }}> + + + + + + ) +} -- cgit 1.4.1