/* eslint-disable react-native/no-inline-styles */ import * as React from 'react'; import { Alert, View, Text, StyleSheet, findNodeHandle, TouchableOpacity, Animated } from 'react-native'; import { Helpers, Colors } from 'react-native-ios-utilities'; import { ContextMenuView, WrapperView, type WrapperViewRef } from 'react-native-ios-context-menu'; import type { ExampleItemProps } from './SharedExampleTypes'; import { ContextMenuCard } from '../components/ContextMenuCard'; const MENU_ITEM_DICT = { reply: 'reply', remove_reactions: 'remove_reactions', undo_send: 'undo_send', delete: 'delete', }; const REACTIONS_DICT = { like : "👍", laugh : "😂", crying: "😭", sad : "😔", heart : "💖", love : "🥰", }; type ReactionKeys = keyof typeof REACTIONS_DICT; const REACTIONS_KEYS = Object.keys(REACTIONS_DICT) as ReactionKeys[]; export function ContextMenuAuxPreviewTest01(props: ExampleItemProps) { const [targetViewNode, setTargetViewNode] = React.useState(null); const [currentReaction, setCurrentReaction] = React.useState(null); const [currentVisibleReaction, setCurrentVisibleReaction] = React.useState(null); const hasReaction = (currentVisibleReaction != null) const viewRef = React.useRef(); const menuRef = React.useRef(); const onPressReaction = React.useCallback((reactionKey: ReactionKeys) => { setCurrentReaction(prev => prev === reactionKey? null : reactionKey ); }, []); const fadeAnimation = React.useRef(new Animated.Value(0)).current; const fadeIn = () => { return new Promise(resolve => { Animated.timing(fadeAnimation, { toValue: 1, duration: 300, useNativeDriver: true, }).start(resolve); }); }; const fadeOut = () => { return new Promise(resolve => { Animated.timing(fadeAnimation, { toValue: 0, duration: 300, useNativeDriver: true, }).start(resolve); }); }; return ( ( {REACTIONS_KEYS.map((reactionKey, index) => ( { onPressReaction(reactionKey); await Helpers.timeout((currentReaction == null)? 550 : 200); menuRef.current.dismissMenu(); }} > {REACTIONS_DICT[reactionKey]} ))} )} onPressMenuItem={({nativeEvent}) => { switch(nativeEvent.actionKey){ case MENU_ITEM_DICT.remove_reactions: setCurrentReaction(null); break; case MENU_ITEM_DICT.undo_send: Alert.alert( 'naurrr', `the tea cannot be unspilled babes, sorry xoxo` ); break; default: Alert.alert( 'onPressMenuItem Event', `actionKey: ${nativeEvent.actionKey} - actionTitle: ${nativeEvent.actionTitle}` ); }; }} onMenuDidHide={async () => { (currentVisibleReaction != null) && await fadeOut(); setCurrentVisibleReaction(currentReaction); (currentReaction != null) && await fadeIn(); }} > {'Bb'} viewRef.current = r} > {"ghorl the tea is piping hawt\nmy wig is in orbittttt"} {hasReaction && ( {REACTIONS_DICT[currentVisibleReaction]} )} ); }; const styles = StyleSheet.create({ auxRootContainer: { flexDirection: 'row', backgroundColor: 'white', borderRadius: 10, paddingHorizontal: 15, paddingVertical: 8, }, demoContainer: { flexDirection: 'row', alignItems: 'center', marginTop: 15, }, messageContainer: { backgroundColor: 'rgba(255,255,255,0.5)', paddingVertical: 10, paddingHorizontal: 15, borderRadius: 10, marginLeft: 10, }, messageText: { fontSize: 14, fontWeight: '300', }, auxPreviewreactionEmojiButton: { }, auxPreviewReactionEmojiButtonSelected: { backgroundColor: Colors.BLUE[100], borderRadius: 7, }, auxPreviewLabelReactionEmoji: { fontSize: 30, }, messageReactionContainer: { alignItems: 'center', justifyContent: 'center', marginLeft: 10, }, messageReactionLabel: { fontSize: 32, }, avatarContainer: { width: 45, height: 45, alignItems: 'center', justifyContent: 'center', backgroundColor: Colors.PURPLE[100], borderRadius: 45/2, }, avatarText: { color: Colors.PURPLE[900], fontWeight: '500', }, });