diff options
| author | Akshay Nair <phenax5@gmail.com> | 2024-09-28 22:19:31 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2024-09-29 16:16:39 +0530 |
| commit | 34b8c1f962a5c835351dc6f4369757259998af16 (patch) | |
| tree | 6f836fdaaedfec125b1202f3b5f9ce24e6277f11 /src/components/Favorites.tsx | |
| parent | a1143f3696a0b272018f7eea43ee23a674c618e1 (diff) | |
| download | daft-launcher-34b8c1f962a5c835351dc6f4369757259998af16.tar.gz daft-launcher-34b8c1f962a5c835351dc6f4369757259998af16.zip | |
Finish up app menu + fix drag interaction
Diffstat (limited to '')
| -rw-r--r-- | src/components/Favorites.tsx | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/src/components/Favorites.tsx b/src/components/Favorites.tsx index c2adae7..6ee99cb 100644 --- a/src/components/Favorites.tsx +++ b/src/components/Favorites.tsx @@ -9,12 +9,23 @@ import DraggableFlatList, { } from 'react-native-draggable-flatlist'; import Icon from 'react-native-vector-icons/MaterialIcons'; import {AppMenu} from './AppMenu'; +import {useInstalledApps} from '../hooks/useInstalledApps'; -export const Favorites: React.FC<{apps: AppDetail[]; active: boolean}> = ({ - apps, - active, -}) => { - const {favoriteAppNames, setFavorites, refreshFavorites} = useFavorites(); +const AppLabel: React.FC<{app: AppDetail}> = React.memo(({app}) => { + return ( + <View className="flex-1"> + <AppMenu app={app}> + <View className="py-3 px-2"> + <Text className="text-lg">{app.label}</Text> + </View> + </AppMenu> + </View> + ); +}); + +export const Favorites: React.FC<{active: boolean}> = (_) => { + const {apps} = useInstalledApps(); + const {favoriteAppNames, setFavorites} = useFavorites(); const appByName = useMemo( () => Object.fromEntries(apps.map((app) => [app.packageName, app])), @@ -33,40 +44,33 @@ export const Favorites: React.FC<{apps: AppDetail[]; active: boolean}> = ({ [setFavorites], ); - useEffect(() => { - if (!active) return; - refreshFavorites(); - }, [active, refreshFavorites]); - return ( <View className="px-4 py-1"> <DraggableFlatList data={favoriteApps} onDragEnd={onDragEnd} - keyExtractor={(item) => item.packageName} + keyExtractor={(app) => app.packageName} renderItem={({item: app, drag, isActive}) => ( - <ShadowDecorator> + <ShadowDecorator key={app.packageName}> <OpacityDecorator> - <AppMenu app={app}> - <View - className={`py-3 px-2 flex-row w-full ${ - isActive ? 'bg-gray-950 opacity-60' : '' - }`}> - <Text className="text-lg flex-1">{app.label}</Text> - <TouchableOpacity - onLongPress={drag} - disabled={isActive} - delayLongPress={500}> - <View className="py-1"> - <Icon name="drag-indicator" size={21} color="#444" /> - </View> - </TouchableOpacity> - </View> - </AppMenu> + <View + className={`flex-row justify-stretch items-center ${ + isActive ? 'bg-[#181818] opacity-60' : '' + }`}> + <AppLabel app={app} /> + + <TouchableOpacity + onLongPress={drag} + disabled={isActive} + hitSlop={10} + className="p-3"> + <Icon name="drag-indicator" size={21} color="#444" /> + </TouchableOpacity> + </View> </OpacityDecorator> </ShadowDecorator> )} - renderPlaceholder={() => <View className="flex-1 bg-gray-950" />} + renderPlaceholder={() => <View className="flex-1 bg-[#181818]" />} /> </View> ); |
