Skip to content

Commit

Permalink
fix: closing keyboard after key press (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlaessig authored Dec 30, 2024
1 parent aa038d0 commit 6bc9313
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function defaultKeyExtractor(_: unknown, index: number): string {
return `key-${index}`;
}

function defaultRenderItem<Item>({ item }: ListRenderItemInfo<Item>): React.ReactElement {
function defaultRenderItems<Item>({ item }: ListRenderItemInfo<Item>): React.ReactElement {
return <Text>{String(item)}</Text>;
}

Expand All @@ -43,48 +43,46 @@ export const AutocompleteInput = React.forwardRef(function AutocompleteInputComp
onShowResults,
onStartShouldSetResponderCapture = () => false,
renderResultList: ResultList = FlatList,
renderTextInput: AutocompleteTextInput = TextInput,
renderTextInput: AutoCompleteTextInput = TextInput,
flatListProps,
style,
...textInputProps
} = props;

function ResultListWrapper(): React.ReactElement {
const resultListProps: FlatListProps<Item> = {
function renderResultList(): React.ReactElement {
const listProps: FlatListProps<Item> = {
data,
renderItem: defaultRenderItem,
renderItem: defaultRenderItems,
keyExtractor: defaultKeyExtractor,
...flatListProps,
style: [styles.list, flatListProps?.style],
};

return <ResultList {...resultListProps} />;
return <ResultList {...listProps} />;
}

function TextInputWrapper(): React.ReactElement {
const autocompleteTextInputProps = {
function renderTextInput(): React.ReactElement {
const renderProps = {
...textInputProps,
style: [styles.input, style],
ref,
};

return <AutocompleteTextInput {...autocompleteTextInputProps} />;
return <AutoCompleteTextInput {...renderProps} />;
}

const showResults = data.length > 0;
onShowResults?.(showResults);

return (
<View style={[styles.container, containerStyle]}>
<View style={[styles.inputContainer, inputContainerStyle]}>
<TextInputWrapper />
</View>
<View style={[styles.inputContainer, inputContainerStyle]}>{renderTextInput()}</View>
{!hideResults && (
<View
style={listContainerStyle}
onStartShouldSetResponderCapture={onStartShouldSetResponderCapture}
>
{showResults && <ResultListWrapper />}
{showResults && renderResultList()}
</View>
)}
</View>
Expand Down

0 comments on commit 6bc9313

Please sign in to comment.