So, when I click one of the results, the 'onPress' is fired, but the result section don't hide. This happens only if there is an 'onPress' function defined
For example, my onPress had this simple function: console.log(details.geometry.location). In this case, results were hidden after click, as expected.
Next time, my function got complicated and it had something like: this.handlePress(details.geometry.location). This time, results didn't hide. I am quite sure handlePress is not causing any issue, it only has setState within it. That's a very simple thing, right? Anything other than console.log keeps the result from hiding. I think it's a bug
Yes, i made a test with a set timeout then a setState just to see what was going on, it brings it back up on re render. I ended up adding a shouldComponentUpdate() and setting it to false to allow for the list to be closed.
the shouldComponentUpdate function should return false for any set state done in the onPress function
shouldComponentUpdate(nextProps, nextState){
if(this.state.locationData != nextState.locationData) {
return false;
}
if(this.state.locationDetails != nextState.locationDetails) {
return false;
}
if(this.state.address != nextState.address) {
return false;
}
return true;
}
the on press function
onPress={(data, details = null) => {
this.setState({ locationDetails:details });
this.setState({ locationData:data });
this.setState({ address: data.description });
}}
you can do that by changing the state listViewDisplayed after you call OnPress
listViewDisplayed={this.state.listViewDisplayed}
@i1990jain That makes the results section disappear when a result is clicked, but then later when state is set again, e.g. by the user pressing on some other button in the UI, the results reappear.
@ibrahimsenan's solution worked for me. Example code:
<GooglePlacesAutocomplete
...
listViewDisplayed={this.state.listViewDisplayed}
onPress={()=>this.setState({listViewDisplayed: false})}
/>
GooglePlacesAutocomplete automatically takes care of setting listViewDisplayed to true when the user is typing their search terms.
This library sadly is overcomplicated, glitchy, and poorly documented. Thanks for the tip!
This library sadly is overcomplicated, glitchy, and poorly documented. Thanks for the tip!
Is it a violation of code of conduct?
There is no reproduction here, so it's very difficult to tell if this is a bug.
Also seems as though this might be covered by the listViewDisplayed prop.
Feel free to open a new issue if this is still a problem.
Most helpful comment
@ibrahimsenan's solution worked for me. Example code:
GooglePlacesAutocomplete automatically takes care of setting listViewDisplayed to true when the user is typing their search terms.