import {Text, View, Modal, TouchableOpacity, Pressable} from 'react-native'; import {AppDetail} from 'react-native-launcher-kit/typescript/Interfaces/InstalledApps'; import {useFavorites} from '../hooks/useFavorites'; import React, {useState} from 'react'; import IntentLauncher from '@angelkrak/react-native-intent-launcher'; export const AppMenu: React.FC> = ({ app, children, }) => { const [isOpen, setIsOpen] = useState(false); const {addToFavorites, isFavorite, removeFromFavorites} = useFavorites(); const menuPress = (fn: () => Promise | void) => async () => { await fn(); setIsOpen(false); }; const menuItems = [ isFavorite(app.packageName) ? { label: 'Remove from favorites', onPress: menuPress(() => removeFromFavorites(app.packageName)), } : { label: 'Add to favorites', onPress: menuPress(() => addToFavorites(app.packageName)), }, { label: 'App info', onPress: menuPress(() => IntentLauncher.startActivity({ action: 'android.settings.APPLICATION_DETAILS_SETTINGS', data: 'package:' + app.packageName, }), ), }, { label: 'Uninstall', onPress: menuPress(() => IntentLauncher.startActivity({ action: 'android.intent.action.DELETE', data: 'package:' + app.packageName, }), ), }, ]; return ( <> setIsOpen(true)}> {children} setIsOpen(false)}> setIsOpen(false)}> {menuItems.map((menuItem) => ( {menuItem.label} ))} ); };