2017-04-30 4 views
0

react-native-mapsreact-native-google-places-autocomplete을 사용하여 위치 기반 iOS 앱을 구축하고 있습니다.React Native : 다른 구성 요소 위에있는 구성 요소

제 코드에는 검색 바코드와지도 코드가 두 번째로 있습니다. 검색 막대가지도 맨 위에 렌더링되도록하는 코드입니다. 문제는 검색 막대 구성 요소가 전체 화면을 차지하는 투명한 요소를 갖고 있기 때문에지도를 이동할 수 없다는 것입니다. 검색 창을 제거하면지도를 이동할 수 있습니다. 검색 막대를지도 상단에 놓고지도를 이동하려면 어떻게해야합니까?

내가하고 싶은 일을하는 대안/더 좋은 방법을 환영합니다.

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); 

Component overlay problem

+1

이것은'ListView'을 가지고 사용하고있는 구성 요소,'GooglePlacesAutocomplete' 때문에 가능성이 그 따라서 화면의 경계에 맞추기 때문에 포함 된보기도지도에 대한 터치 이벤트를 차단하는보기를 수행합니다. – sooper

답변

1

react-native-google-places-autocomplete 스타일 속성 위치 스타일을 추가

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