[Bug] onFocus prop from textInputProps causes the list view not to display
See original GitHub issueBug Description:
Using onFocus prop from textInputProps causes the list view not to display
Reproduction - This my autocomplete implementation:
<GooglePlacesAutocomplete
ref={(input) => {
textInput = input;
}}
textInputProps={{
onChangeText: (text) => {
this.setState({
formatted_address: text,
selected_street_address:
text.indexOf(',') > -1 ? text.substring(0, text.indexOf(',')) : text,
selected_address_remainder:
text.indexOf(',') > -1 ? text.substring(text.indexOf(',') + 2) : '',
});
},
onFocus: () => {
this.setState({ top_view_visible: false });
},
}}
styles={{
textInput: { fontSize: verticalScale(12) },
container: { overflow: 'visible', flexGrow: 0, flexShrink: 0, elevation: 200 },
listView: {
position: 'absolute',
top: verticalScale(40),
elevation: 999,
zIndex: 999,
backgroundColor: 'white',
},
}}
scrollEnabled={true}
placeholder="Search"
minLength={1}
autoFocus={true}
returnKeyType={'search'}
listViewDisplayed={'auto'}
fetchDetails={true}
onPress={(data, details = null) => {
// 'details' is provided when fetchDetails = true
LogsHelper.info({ tag: this.TAG, message: 'Data:' + JSON.stringify(data) });
LogsHelper.info({
tag: this.TAG,
message: 'Details: ' + JSON.stringify(details?.formatted_address),
});
textInput.setAddressText(details?.formatted_address);
this.setState({
selected_street_address: details?.formatted_address.substring(
0,
details?.formatted_address.indexOf(','),
),
selected_address_remainder: details?.formatted_address.substring(
details?.formatted_address.indexOf(',') + 2,
),
});
}}
query={{
key: 'xxx......',
language: 'en',
}}
/>
I am using:
-
Library Version: 1.7.3
-
React Native Version: 0.61.5
-
Ejected Expo
-
iOS
-
Android
-
Web
first screen shot you can see autocomplete is working on emulator with onFocus commented out
Once I uncomment onFocus:
Important Note: setting state inside onFocus is the issue. if I replace that line with a log, the list works and the log prints. is this a bug or am I doing something wrong?
Issue Analytics
- State:
- Created 3 years ago
- Comments:9
Top Results From Across the Web
In React ES6, why does the input field lose focus after typing a ...
Every time your state/prop change, the function returns a new form. it caused you to lose focus. Try putting what's inside the function...
Read more >[v6] fields losing focus after first onChange #1094 - GitHub
The losing focus bug is not a bug. It's the expected React behavior. If you are defining your component as an arrow function...
Read more >Scroll to a Specific Item in ScrollView List View - About React
In this example, we will create a List using Scroll View to hold the data, a TextInput and a button to take the...
Read more >A complete guide to TextInput in React Native - LogRocket Blog
In this article, you will learn the basics of React Native's TextInput component. Later on, we will also tailor its properties according to...
Read more >react-native-google-places-autocomplete - npm
See more in the releases section. ... Google Places API keys and enable "Google Places API Web Service" (NOT Android or iOS) in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Will do. I wont be able to do that before at least 24 hours as I’m about to travel. Please don’t close the issue.
@bell-steven your suggestion works perfectly. Thank you so much for all your help. I am closing this issue now. Thanks again 😃