import React from 'react'; import { View, Text, TouchableOpacity, Modal, ScrollView, Pressable, Dimensions } from 'react-native'; import Icon from '~/components/atoms/Icon'; import { useTheme } from '~/features/theme/ThemeProvider'; interface AndroidContextMenuProps { actions: Array<{ title: string; iconName?: string; iconColor?: string; id: string; }>; onPress: (action: any) => void; children: React.ReactNode; } /** * Custom Android Context Menu with Ionicons support * * This component wraps the native ContextMenu on Android to add icon support * using Ionicons instead of emojis. */ export const AndroidContextMenu: React.FC = ({ actions, onPress, children, }) => { const [visible, setVisible] = React.useState(false); const [menuPosition, setMenuPosition] = React.useState({ x: 0, y: 0 }); const { isDark, tw } = useTheme(); const childRef = React.useRef(null); const showMenu = () => { if (childRef.current) { childRef.current.measure((x, y, width, height, pageX, pageY) => { // Position menu to the left of the button to ensure it's fully visible const menuWidth = 280; const screenWidth = Dimensions.get('window').width; const menuX = Math.max(20, Math.min(pageX - menuWidth + width, screenWidth - menuWidth - 20)); // Reduce the top offset for Android - use a smaller gap const menuY = pageY + height - 8; // Reduced from pageY + height to have less gap setMenuPosition({ x: menuX, y: menuY }); setVisible(true); }); } }; const handleActionPress = (action: any, index: number) => { setVisible(false); // Simulate native event structure onPress({ nativeEvent: { index, name: action.title, } }); }; const menuBackgroundColor = isDark ? 'rgba(30, 30, 30, 0.98)' : 'rgba(250, 250, 250, 0.98)'; const textColor = isDark ? '#FFFFFF' : '#000000'; return ( <> {children} setVisible(false)} animationType="fade" > setVisible(false)} > {actions.map((action, index) => ( handleActionPress(action, index)} style={{ flexDirection: 'row', alignItems: 'center', padding: 12, borderRadius: 8, }} activeOpacity={0.7} > {action.iconName && ( <> )} {action.title} ))} ); };