Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-native AutoComplete text input [closed]

For example, I have a list of towns. I need to create something like this

How to create it (for Android and IOS)? And where I should to store it?

like image 212
zlFast Avatar asked Feb 15 '16 13:02

zlFast


People also ask

How do I disable text input in React Native?

To disable options on React Native TextInput, we can set the editable and selectTextOnFocus props to false . to set them both to false . Then we won't see any popup options displayed when we focus on the text input. editable set to false disables typing in the input.

How do you get suggestions while typing in text input in React Native?

Just show a view beneath the TextInput that will contain a list of matching words with the input text, and you can control that views visibility when user selects a word from the list. Dont forget to make it absolute.

How do you clear input field after submit React Native?

To clear input values after form submit in React: Store the values of the input fields in state variables. Set the onSubmit prop on the form element. When the submit button is clicked, set the state variables to empty strings.


1 Answers

OK, so based on the little information you've given us, I tried to make a quick example (no design at all) that you can find here

I'll let you do the styling.

Reading your data from the JSON file : check this

The code is the following :

'use strict';

var React = require('react-native');
var {
  AppRegistry,
  Component,
  StyleSheet,
  Text,
  TextInput,
  ListView,
  View,
} = React;

var adresses = [
  {
    street: "1 Martin Place",
      city: "Sydney",
    country: "Australia"
    },{
    street: "1 Martin Street",
      city: "Sydney",
    country: "Australia"
  }
];

var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});

class SampleApp extends Component {
  constructor(props) {
    super(props);

    this.state = {
      searchedAdresses: []
    };
  };

  searchedAdresses = (searchedText) => {
    var searchedAdresses = adresses.filter(function(adress) {
      return adress.street.toLowerCase().indexOf(searchedText.toLowerCase()) > -1;
    });
    this.setState({searchedAdresses: searchedAdresses});
  };

    renderAdress = (adress) => {
    return (
      <View>
        <Text>{adress.street}, {adress.city}, {adress.country}</Text>
      </View>
    );
  };
  render() {
    return (
      <View style={styles.container}>
        <TextInput 
            style={styles.textinput}
            onChangeText={this.searchedAdresses}
            placeholder="Type your adress here" />
        <ListView
                    dataSource={ds.cloneWithRows(this.state.searchedAdresses)}
          renderRow={this.renderAdress} />
      </View>
    );
  };
}

var styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#FFFFFF',
  },
  textinput: {
    marginTop: 30,
    backgroundColor: '#DDDDDD',
    height: 40,
    width: 200
  }
});

AppRegistry.registerComponent('SampleApp', () => SampleApp);
like image 182
G. Hamaide Avatar answered Sep 20 '22 08:09

G. Hamaide