Last active
September 30, 2017 11:29
-
-
Save hanipcode/6fe87425028d4fb196f140040601469b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component } from 'react'; | |
| import { StyleSheet, Text, View } from 'react-native'; | |
| import AutoCompleteBox from '../components/AutoCompleteBox'; | |
| import AutoCompleteResultList from '../components/AutoCompleteResultList'; | |
| import { getPredictionWithDetail } from '../services.js'; | |
| const KEY = 'Y_API_KEY'; | |
| class SearchBox extends Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| query: '', | |
| data: [], | |
| loading: false | |
| }; | |
| } | |
| onChangeText(query) { | |
| this.setState({ query }); | |
| getPredictionWithDetail(query, KEY).then(result => { | |
| this.setState({ data: result, loading: false }); | |
| }); | |
| } | |
| _finishResult(text) { | |
| this.setState({ query: text, data: [] }); | |
| } | |
| _onItemClick(geometry) { | |
| this.props.onItemClick(geometry); | |
| } | |
| render() { | |
| return ( | |
| <View style={{ position: 'absolute', top: 0, left: 0, right: 0 }}> | |
| <AutoCompleteBox | |
| placeholder={this.props.placeholder || 'Masukan Nama Tempat'} | |
| value={this.state.query} | |
| onChangeText={query => this.onChangeText(query)} | |
| /> | |
| <AutoCompleteResultList | |
| data={this.state.data} | |
| onItemClick={geometry => this._onItemClick(geometry)} | |
| finishResult={text => this._finishResult(text)} | |
| /> | |
| </View> | |
| ); | |
| } | |
| } | |
| export default SearchBox; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment