[英]ViewPager and GooglePlacesAutocomplete don't work together in React Native under Expo
I have a GooglePlacesAutocomplete component inside a ViewPager component, but apparently they're not working well together for iOS.我在ViewPager组件中有一个GooglePlacesAutocomplete组件,但显然它们在 iOS 上不能很好地协同工作。
It works fine with Android.它适用于Android。
In this code, it pretty much loops through a list of components and displays them using ViewPager horizontally.在这段代码中,它几乎遍历了一个组件列表,并使用 ViewPager 水平显示它们。
<View style={styles.container}>
<ViewPager
keyboardDismissMode={"on-drag"}
style={styles.viewPager}
ref={viewPager => {
this.viewPager = viewPager
}}
onPageSelected={page => {
this.setState({ currentPage: page.position })
}}>
{PAGES.map( (page, index) => this.renderViewPagerPage(page, index))}
</ViewPager>
</View>
This other code is just importing the component for the Places API with a bunch of styles and flags for it.其他代码只是为 Places API 导入带有一堆样式和标志的组件。
{
return (
<View>
<Text style={styles.header}>Pick Up Location</Text>
<GooglePlacesAutocomplete
onPress={() => console.log('pressed')}
styles={{
container: {
position: "absolute",
top: 40,
width: "100%",
},
textInputContainer: {
flex: 1,
backgroundColor: "transparent",
height: 54,
marginHorizontal: 0,
borderTopWidth: 0,
borderBottomWidth: 0,
paddingBottom: 50,
},
textInput: {
height: 54,
margin: 0,
borderRadius: 0,
paddingTop: 0,
paddingBottom: 0,
paddingLeft: 20,
paddingRight: 20,
marginTop: 0,
marginLeft: 0,
marginRight: 0,
elevation: 5,
shadowColor: "#000",
shadowOpacity: 0.1,
shadowOffset: { x: 0, y: 0 },
shadowRadius: 15,
borderWidth: 1,
borderColor: "#ddd",
fontSize: 18,
},
listView: {
borderWidth: 1,
borderColor: "#ddd",
backgroundColor: "#fff",
marginHorizontal: 20,
elevation: 5,
shadowColor: "#000",
shadowOpacity: 0.1,
shadowOffset: { x: 1, y: 0},
shadowRadius: 15,
marginTop: 10,
},
description: {
fontSize: 16
},
row: {
padding: 20,
height: 58,}
}}
keyboardShouldPersistTaps='always'
placeholder="Placeholder"
keyboardAppearance={'dark'} // Can be left out for default keyboardAppearance https://facebook.github.io/react-native/docs/textinput.html#keyboardappearance
placeholderTextColor="#333"
returnKeyType={'default'}
onPress={(data, details) => {
console.log(data['description']);
}}
currentLocationLabel="Current location"
currentLocation={true} // Will add a 'Current location' button at the top of the predefined places list
query={{
key: GOOGLE_MAPS_API_KEY,
language: "en",
components: 'country:pr'
}}
textInputProps={{
autoCapitalize: "none",
autoCorrect: false
}}
fetchDetails={false}
enablePoweredByContainer={true}
/>
</View>
);
}
}
I have a ViewPager which is essentially a type of carousel, in which inside will have an AutoComplete input container using Google's Places API.我有一个 ViewPager,它本质上是一种轮播,其中内部将有一个使用 Google Places API 的 AutoComplete 输入容器。
It works fine outside of the ViewPager component, but when it's inside of it, I can't click the autocomplete list view that it pops while auto completing the text.它在 ViewPager 组件之外工作正常,但是当它在它内部时,我无法单击它在自动完成文本时弹出的自动完成列表视图。
The parent component needed to also have:父组件还需要具有:
keyboardShouldPersistTaps={"always"}
<ViewPager
keyboardShouldPersistTaps={"always"}
keyboardDismissMode={"on-drag"}
style={styles.viewPager}
ref={viewPager => {
this.viewPager = viewPager
}}
onPageSelected={page => {
this.setState({ currentPage: page.position })
}}>
{PAGES.map( (page, index) => this.renderViewPagerPage(page, index))}
</ViewPager>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.