1.0.1 • Published 3 years ago

@mad-family-ui/react-native-autocomplete v1.0.1

Weekly downloads
89
License
ISC
Repository
github
Last release
3 years ago

react-native-autocomplete

A pure TypeScript autocomplete component for React Native (iOS) (Android - Not working completely).

Autocomplete Example

How to use react-native-autocomplete

Installation

$ npm install --save @mad-family-ui/react-native-autocomplete

Example

// ...

  return (
    <Autocomplete
        list={[
          {name: 'Apple', value: 'apple'},
          {name: 'Orange', value: 'orange'},
          {name: 'Grape', value: 'grape'},
          {name: 'Banana', value: 'banana'},
        ]}
        labelKey="name"
        valueKey="value"
     />
  );

// ...

A complete example for iOS can be found here.

Props

PropTypeDescription
list*Array of objectList of objects used as the data for the Autocomplete
zIndexnumberthe container component will have this zIndex set. Useful when you have multiple Autocomplete in 1 Screen
containerHeightstring / numberThe outermost container height
labelKey*stringThe key searched for in the list for showing the text in the autocomplete suggestion list
valueKey*stringThe key searched for in the list for finding selected item
searchKeys*Array of stringsThis array of keys is used to filter out the suggestions from the list of objects passed
onSelectItem*(item: any) => voidWhen Item is selected, this function is invoked to return the selected item.
defaultValuestringIf provided, will find the item from list using valueKey and set it selected by default
containerStylestyleThese styles will be applied to the container which surrounds the autocomplete component.
listContainerStylestyleThese styles will be applied to the container which surrounds the autocomplete suggestion list component (ScrollView).
inputContainerStylestyleThese styles will be applied to the input container which surrounds the input component.
inputStylestyleThese styles will be applied to the input component.
listItemContainerStylestyleThese styles will be applied to the container which surrounds the suggestion item component.
listItemTextStylestyleThese styles will be applied to the suggestion item.
customItemRenderer(item: any, index: number) => React.ReactElementCustom Item Renderer
noResultComponentReact.ReactElementCustom No Result Component
theme"light"/"dark"Support for dark and light theme. Useful if creating an app when you are supporting phone theme used

Android

  • To make this component work on Android, we need to specify the containerHeight property as Android cannot detect clicks in absolute positioning.

Changelog

1.0.0

  • Used Flatlist instead of Scrollview for performance improvements.

Contribute

  • Android has issues with able to detect clicks with absolute positioning. If you could help solve this issue, please help :)
  • Feel free to open issues or do a PR!