React Native:组件位于另一个组件之上

用户名

我正在使用react-native-maps构建基于位置的iOS应用react-native-google-places-autocomplete

在我的代码中,我首先拥有搜索条形码,其次是地图代码-这样搜索栏就会呈现在地图顶部。问题是,我无法移动地图,因为搜索栏组件似乎具有透明元素,占据了整个屏幕。删除搜索栏后,我可以移动地图。如何将搜索栏放在地图顶部,以及如何移动地图。

我欢迎其他/更好的方式来做我想做的事情。

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Dimensions
} from 'react-native';
import MapView from 'react-native-maps';
var {GooglePlacesAutocomplete} = require('react-native-google-places-autocomplete');

const homePlace = {description: 'Home', geometry: { location: { lat: 42.3969, lng: -71.1224 } }};
const workPlace = {description: 'Work', geometry: { location: { lat: 42.3, lng: -71.1 } }};

var screenWidth = Dimensions.get('window').width;

export default class myapp extends Component {
  render() {
    return (
    <View style={styles.container}>


        <MapView
            style={styles.map}
            initialRegion={{
                latitude: 42.3967,
                longitude: -71.1223,
                latitudeDelta: 0.0922,
                longitudeDelta: 0.0421,
            }}>
            <MapView.Marker
                coordinate={{
                    latitude: 42.3967,
                    longitude: -71.1223
                }}/>
        </MapView>



        <GooglePlacesAutocomplete
            placeholder='Search location'
            minLength={2}
            autoFocus={false}
            autoCorrect={false}
            listViewDisplayed='auto'        // true/false/undefined
            fetchDetails={true}
            renderDescription={(row) => row.description}    // custom description render
            onPress={(data, details = null) => {    // 'details' is provided when fetchDetails = true
                console.log(data)
                console.log(details)
            }}
            getDefaultValue={() => {
                return '';      // text input default value
            }}
            query={{
                // available options: https://developers.google.com/places/web-service/autocomplete
                key: 'AIzaSyAUYfbKtctkIibOgFnNN2x9Xg9i0sVxlhQ',
                language: 'en',
                types: 'geocode'
            }}
            styles={{
                description: {
                    fontWeight: 'bold',
                },
                predefinedPlacesDescription: {
                    color: '#1faadb',
                },
                textInputContainer: {
                    backgroundColor: 'rgba(0,0,0,0)',
                    top: 15,
                    width: screenWidth-10,
                    borderWidth: 0
                },
                textInput: {
                    marginLeft: 0,
                    marginRight: 0,
                    height: 38,
                    color: '#5d5d5d',
                    fontSize: 16,
                    borderWidth: 0
                },
                listView: {
                    backgroundColor: 'rgba(192,192,192,0.9)',
                    top: 23
                }
            }}

            currentLocation={true}
            currentLocationLabel="Current location"
            nearbyPlacesAPI='GooglePlacesSearch'
            GoogleReverseGeocodingQuery={{
                // available options for GoogleReverseGeocoding API : https://developers.google.com/maps/documentation/geocoding/intro
            }}
            GooglePlacesSearchQuery={{
                // available options for GooglePlacesSearch API : https://developers.google.com/places/web-service/search
                rankby: 'distance',
                types: 'food'
            }}

            filterReverseGeocodingByTypes={['locality', 'administrative_area_level_3', 'sublocality', 'administrative_area_level_2', 'administrative_area_level_1']}
            // filter the reverse geocoding results by types - ['locality', 'administrative_area_level_3'] if you want to display only cities

            predefinedPlaces={[homePlace, workPlace]}

            debounce={200}
            //renderLeftButton={() => <Image source={require('left-icon')} />}
            renderLeftButton={() => <Text></Text> }
            renderRightButton={() => <Text></Text> }


        />


      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  map: {
    left: 0,
    right: 0,
    top: 0,
    bottom: 0,
    position: 'absolute'
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

AppRegistry.registerComponent('myapp', () => myapp);

组件重叠问题

迈萨姆·伊扎德梅尔

将位置样式添加到react-native-google-places-autocomplete样式属性:

styles={{
          container:{
            position: 'absolute',
            top: 0
          },
            description: {
                fontWeight: 'bold',
            },
          .....

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使React组件位于另一个组件之上

如何在React中让一个组件“位于另一个组件之下”?

React Native,从一个组件导航到另一个组件

React Native将Text组件添加到另一个Text组件中

React Native 测试组件依赖于另一个组件

从另一个组件到达在组件内声明的对象 - React Native

React - 另一个组件内的组件

React:在另一个组件中使用组件

React Native将一个组件插入另一个

React Native - 将数据从一个组件传递到另一个

如何在React Native中从另一个功能组件更改一个功能组件的状态?

无法使用 React Native 将值从一个组件传递到另一个组件

如何在另一个组件渲染后渲染一个React Native组件?

在React-native中将一个组件的状态更改为另一个组件的状态

react native - 如何将参数从一个组件传递到另一个组件?

如何从 react-native 中的另一个功能组件访问一个功能组件的状态?

React Native使用另一个函数循环返回多个JSX组件

我的按钮无法更改另一个React Native组件中的状态

在 React Native 中导航时,如何从另一个组件调用函数?

来自另一个组件的 (react-native) 函数不会返回我的值

如何从React-Native中的另一个组件打开/关闭Drawer

如何在React Native的另一个组件中使用ref?

如何在另一个文件中获取组件的状态 react native

无法调用或更新另一个组件 React Native 的状态

如何在React Native中导航到类组件中的另一个屏幕

从另一个组件更改React Native App.js中的状态

React Native-将状态传递给另一个组件

如何从另一个文件获取React Native导航负载组件?

我如何在React Native中从另一个组件调用函数?