MCPcopy Index your code
hub / github.com/byteburgers/react-native-autocomplete-input

github.com/byteburgers/react-native-autocomplete-input @v5.5.6

Chat with this repo
repository ↗ · DeepWiki ↗ · release v5.5.6 ↗ · + Follow
17 symbols 37 edges 10 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

react-native-autocomplete-input

npm version Test

A pure JS autocomplete component for React Native written in TypeScript. Use this component in your own projects or use it as inspiration to build your own autocomplete.

Autocomplete Example

Play around with the Example Snack

Installation

# Install with npm
$ npm install --save react-native-autocomplete-input

# Install with yarn
$ yarn add react-native-autocomplete-input

Example

function MyComponent() {
  const [ query, setQuery ] = useState('');
  const data = useFilteredData(query);

  return (
    <Autocomplete
      data={data}
      value={query}
      onChangeText={(text) => setQuery(text)}
      flatListProps={{
        keyExtractor: (_, idx) => idx,
        renderItem: ({ item }) => <Text>{item}</Text>,
      }}
    />
  );
}

Android

Android does not support overflows (#20), for that reason it is necessary to wrap the autocomplete into a absolute positioned view on Android. This will allow the suggestion list to overlap other views inside your component.

function MyComponent() {
  return (
    <View>
      <View style={styles.autocompleteContainer}>
        <Autocomplete {/* your props */} />
      </View>
      <View>
        <Text>Some content</Text>
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  autocompleteContainer: {
    flex: 1,
    left: 0,
    position: 'absolute',
    right: 0,
    top: 0,
    zIndex: 1
  }
});

Props

Prop Type Description
containerStyle style These styles will be applied to the container which surrounds the autocomplete component.
hideResults bool Set to true to hide the suggestion list.
data array An array with suggestion items to be rendered in renderItem({ item, i }). Any array with length > 0 will open the suggestion list and any array with length < 1 will hide the list.
inputContainerStyle style These styles will be applied to the container which surrounds the textInput component.
listContainerStyle style These styles will be applied to the container which surrounds the result list.
listStyle style These style will be applied to the result list.
onShowResults function onShowResults will be called when the autocomplete suggestions appear or disappear.
onStartShouldSetResponderCapture function onStartShouldSetResponderCapture will be passed to the result list view container (onStartShouldSetResponderCapture).
renderTextInput function render custom TextInput. All props passed to this function.
flatListProps object custom props to FlatList.
renderResultList function render custom result list. Can be used to replace FlatList. All props passed to this function.

Known issues

  • By default the autocomplete will not behave as expected inside a <ScrollView />. Set the scroll view's prop to fix this: keyboardShouldPersistTaps={true} for RN <= 0.39, or keyboardShouldPersistTaps='always' for RN >= 0.40. (#5). Alternatively, you can use renderResultList to render a custom result list that does not use FlatList. See the tests for an example.
  • If you want to test with Jest add jest.mock('react-native-autocomplete-input', () => 'Autocomplete'); to your test.

Contribute

Feel free to open issues or submit a PR!

Local development

# Install Dependencies
$ npm i

# Locally link the autocomplete package into the example project
$ npm link react-native-autocomplete-input -w starwarsmoviefinder 

# Enable package rebuild on changes
$ npx nx watch --projects=react-native-autocomplete-input -- npm run build 

# Run the example project
$ npm run start -w starwarsmoviefinder

Extension points exported contracts — how you extend this code

Props (Interface)
(no doc)
examples/StarWarsMovieFinder/MovieDetails.tsx

Core symbols most depended-on inside this repo

renderResultList
called by 1
packages/react-native-autocomplete-input/index.tsx
renderTextInput
called by 1
packages/react-native-autocomplete-input/index.tsx
compareTitle
called by 1
examples/StarWarsMovieFinder/swapi.ts
filterMovies
called by 1
examples/StarWarsMovieFinder/swapi.ts
defaultKeyExtractor
called by 0
packages/react-native-autocomplete-input/index.tsx
defaultRenderItems
called by 0
packages/react-native-autocomplete-input/index.tsx
MovieDetails
called by 0
examples/StarWarsMovieFinder/MovieDetails.tsx
constructor
called by 0
examples/StarWarsMovieFinder/swapi.ts

Shape

Function 11
Method 3
Class 2
Interface 1

Languages

TypeScript100%

Modules by API surface

examples/StarWarsMovieFinder/swapi.ts7 symbols
packages/react-native-autocomplete-input/index.tsx4 symbols
packages/react-native-autocomplete-input/__tests__/AutocompleteInput.spec.tsx3 symbols
examples/StarWarsMovieFinder/MovieDetails.tsx2 symbols
examples/StarWarsMovieFinder/App.tsx1 symbols

For agents

$ claude mcp add react-native-autocomplete-input \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page