简体   繁体   English

ViewPager 和 GooglePlacesAutocomplete 在 Expo 下的 React Native 中不能一起工作

[英]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.

相关问题 React Native本地化在设备上不起作用 - React native geolication don't work on device 无法打开,因为您无权查看 - React Native - Expo? - Couldn’t be opened because you don’t have permission to view it - React Native - Expo? ScrollView 水平分页仅适用于 Android 不适用于 IOS react native expo cli - ScrollView horizontal pagination only works on Android doesn't work on IOS react native expo cli Expo GooglePlacesAutocomplete currentLocation 在 iOS 上不起作用 - Expo GooglePlacesAutocomplete currentLocation not working on iOS touchesMoved:withEvent:和UIRotationgestureRecognizer不能一起工作 - touchesMoved:withEvent: and UIRotationgestureRecognizer don't work together GestureRecognizer和IBOutlet不能一起使用 - GestureRecognizer and IBOutlet don't work together UILongPressGestureRecognizer和UITextField无法一起使用 - UILongPressGestureRecognizer and UITextField don't work together AudioStreamer和AVAudioRecorder不能一起使用 - AudioStreamer and AVAudioRecorder don't work together Admob 奖励广告在 Expo App 上的 ios 上不起作用 - Admob reward ads don't work on ios on Expo App Expo react本机应用程序图像在testflight ios上无法正常工作 - Expo react native app image not work properly on testflight ios
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM