diff options
| author | Akshay Nair <phenax5@gmail.com> | 2024-09-28 22:27:22 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2024-09-29 16:16:39 +0530 |
| commit | af2b5a7e618b74319e262cef8e25c1aad83c106b (patch) | |
| tree | f3d639ac923c275cef852c70c0d910b70b5ed5f1 | |
| parent | 34b8c1f962a5c835351dc6f4369757259998af16 (diff) | |
| download | daft-launcher-af2b5a7e618b74319e262cef8e25c1aad83c106b.tar.gz daft-launcher-af2b5a7e618b74319e262cef8e25c1aad83c106b.zip | |
Add clear search text button
| -rw-r--r-- | src/screens/AppList.tsx | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/screens/AppList.tsx b/src/screens/AppList.tsx index adb51b5..4ef5ec3 100644 --- a/src/screens/AppList.tsx +++ b/src/screens/AppList.tsx @@ -1,15 +1,22 @@ import {matchSorter} from 'match-sorter'; import React, {useEffect, useMemo, useRef, useState} from 'react'; -import {ScrollView, Text, TextInput, View} from 'react-native'; +import { + ScrollView, + Text, + TextInput, + TouchableHighlight, + View, +} from 'react-native'; import Icon from 'react-native-vector-icons/MaterialIcons'; import {AppMenu} from '../components/AppMenu'; import {useInstalledApps} from '../hooks/useInstalledApps'; import {AppDetail} from 'react-native-launcher-kit/typescript/Interfaces/InstalledApps'; +import {useStableCallback} from '../hooks/useStableCallback'; const AppListItem: React.FC<{app: AppDetail}> = React.memo(({app}) => { return ( <AppMenu app={app}> - <View className="px-4 py-2"> + <View className="p-2"> <Text className="text-md font-bold">{app.label}</Text> <Text className="text-xs text-gray-600">{app.packageName}</Text> </View> @@ -22,6 +29,8 @@ export const AppList: React.FC<{active: boolean}> = React.memo(({active}) => { const textInputRef = useRef<TextInput>(null); const [searchText, setSearchText] = useState(''); + const clearSearchInput = useStableCallback(() => setSearchText('')); + const filteredApps = useMemo(() => { if (searchText === '') return apps; @@ -35,9 +44,9 @@ export const AppList: React.FC<{active: boolean}> = React.memo(({active}) => { }, [active]); return ( - <View> - <View className="flex justify-between flex-row items-center gap-2"> - <Icon name="search" size={21} color="#aaa" /> + <View className="px-2"> + <View className="flex justify-between flex-row items-center gap-2 px-2"> + <Icon name="search" size={21} color="#555" className="py-2" /> <TextInput ref={textInputRef} autoFocus={false} @@ -46,6 +55,12 @@ export const AppList: React.FC<{active: boolean}> = React.memo(({active}) => { className="flex-1" onChangeText={setSearchText} /> + <TouchableHighlight + underlayColor="#222" + onPress={clearSearchInput} + className="p-2"> + <Icon name="close" size={21} color="#aaa" /> + </TouchableHighlight> </View> <ScrollView contentInsetAdjustmentBehavior="automatic"> |
