Skip to content

Commit

Permalink
feat: optional search clear text
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikDanielewicz committed Mar 20, 2024
1 parent 31aa092 commit 41236d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const SearchBar = () => {
const {
searchPhrase,
setSearchPhrase,
hideSearchBarClearIcon,
translation,
setActiveCategoryIndex,
renderList,
Expand All @@ -19,11 +20,11 @@ export const SearchBar = () => {
} = React.useContext(KeyboardContext)
const inputRef = React.useRef<TextInput>(null)

const handleSearch = async (text: string) => {
const handleSearch = (text: string) => {
setSearchPhrase(text)

if (text === '') {
await setActiveCategoryIndex(0)
setActiveCategoryIndex(0)
setShouldAnimateScroll(enableCategoryChangeAnimation)

return
Expand All @@ -38,8 +39,10 @@ export const SearchBar = () => {
const clearPhrase = () => {
setSearchPhrase('')
clearEmojiTonesData()
inputRef.current?.blur()
setActiveCategoryIndex(0)
setTimeout(() => {
inputRef.current?.blur()
}, 0)
}

return (
Expand All @@ -59,7 +62,7 @@ export const SearchBar = () => {
onTouchEndCapture={clearEmojiTonesData}
placeholderTextColor={theme.search.placeholder}
/>
{!!searchPhrase && (
{!hideSearchBarClearIcon && !!searchPhrase && (
<TouchableOpacity onPress={clearPhrase} style={styles.button}>
<Icon
iconName={'Close'}
Expand Down
2 changes: 2 additions & 0 deletions src/contexts/KeyboardContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export type KeyboardProps = {
enableRecentlyUsed?: boolean
categoryPosition?: CategoryPosition
enableSearchBar?: boolean
hideSearchBarClearIcon?: boolean
categoryOrder?: CategoryTypes[]
onRequestClose?: () => void
disableSafeArea?: boolean
Expand Down Expand Up @@ -163,6 +164,7 @@ export const defaultKeyboardContext: Required<KeyboardProps> & {
enableRecentlyUsed: false,
categoryPosition: 'floating',
enableSearchBar: false,
hideSearchBarClearIcon: false,
categoryOrder: [...CATEGORIES],
onRequestClose: () => {},
disableSafeArea: false,
Expand Down

0 comments on commit 41236d3

Please sign in to comment.