1.0.0 • Published 4 years ago

npm-autocomplate-highlight-words v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

npm-autocomplate-highlight-words

How to use npm-autocomplate-highlight-words

Tested with RN >= 0.26.2. If you want to use RN < 0.26 try to install npm-autocomplate-highlight-words <= 0.0.5.

Installation

$ npm install --save npm-autocomplate-highlight-words

Example

// ...

render() {
  const { query } = this.state;
  const data = this._filterData(query);
  return (
    <Autocomplete
      data={data}
      defaultValue={query}
      onChangeText={text => this.setState({ query: text })}
      renderItem={({ item, i }) => (
        <TouchableOpacity onPress={() => this.setState({ query: item })}>
          <Text>{item}</Text>
        </TouchableOpacity>
      )}
    />
  );
}

// ...
//...

render() {
  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

PropTypeDescription
containerStylestyleThese styles will be applied to the container which surrounds the autocomplete component.
hideResultsboolSet to true to hide the suggestion list.
dataarrayAn 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.
inputContainerStylestyleThese styles will be applied to the container which surrounds the textInput component.
listContainerStylestyleThese styles will be applied to the container which surrounds the result list.
listStylestyleThese style will be applied to the result list.
onShowResultfunctiononShowResult will be called when the autocomplete suggestions appear or disappear.
onStartShouldSetResponderCapturefunctiononStartShouldSetResponderCapture will be passed to the result list view container (onStartShouldSetResponderCapture).
renderItemfunctionrenderItem will be called to render the data objects which will be displayed in the result view below the text input.
keyExtractorfunctionkeyExtractor(item, i) will be called to get key for each item. It's up to you which string to return as a key.
renderSeparatorfunctionrenderSeparator will be called to render the list separators which will be displayed between the list elements in the result view below the text input.
renderTextInputfunctionrender custom TextInput. All props passed to this function.
flatListPropsobjectcustom props to FlatList].

Contribute

Feel free to open issues or do a PR!