Giter Site home page Giter Site logo

jigarvyas / react-native-autocomplete-input Goto Github PK

View Code? Open in Web Editor NEW

This project forked from byteburgers/react-native-autocomplete-input

1.0 2.0 0.0 944 KB

Pure javascript autocomplete input for react-native

License: MIT License

JavaScript 65.67% Python 7.07% Java 6.61% Objective-C 20.65%

react-native-autocomplete-input's Introduction

react-native-autocomplete-input

npm version Build Status

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

Autocomplete Example

How to use react-native-autocomplete-input

Tested with RN >= 0.26.2. If you want to use RN < 0.26 try to install react-native-autocomplete-input <= 0.0.5.

Installation

$ npm install --save react-native-autocomplete-input

or install HEAD from github.com:

$ npm install --save l-urence/react-native-autocomplete-input

Example

// ...

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

// ...

A complete example for Android and iOS can be found here.

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.

//...

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

Prop Type Description
containerStyle style These styles will be applied to the container which surrounds the autocomplete component.
data array An array with suggestion items to be rendered in renderItem(item). 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.
onShowResult function onShowResult will be called when the autocomplete suggestions appear or disappear.
renderItem function renderItem will be called to render the data objects which will be displayed in the result view below the text input.
renderSeparator function renderSeparator will be called to render the list separators which will be displayed between the list elements in the result view below the text input.
renderTextInput function render custom TextInput. 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 keyboardShouldPersistTaps={true} to fix this (#5).
  • 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 do a PR!

react-native-autocomplete-input's People

Contributors

binchik avatar eliseo-juan avatar evansiroky avatar huszy avatar jasontwong avatar kesha-antonov avatar kiraninbng avatar mrlaessig avatar szajbus avatar vonovak avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.