React Native Maps - представление карты не отображается - PullRequest
0 голосов
/ 08 мая 2019

Проблема в том, что карта не отображается.Я пытался применить его с index и position, но ничего не работает.Мне нужна точка зрения другого.Спасибо.

Вот чего я хочу добиться:

enter image description here

Вот мои коды:

return(
  <View style={styles.container}>
    {/* <StatusBar backgroundColor={'transparent'} translucent={true}/> */}
    <MapView
      style={styles.map}
      initialRegion={this.state.focusedLocation}
      onPress={this.pickLocationHandler}
      showsUserLocation={true}
      ref={ref => this.map = ref} //For animating map movement
    >
      {userMarker}
      {this.state.markers.map((marker, index) => {
        const scaleStyle = {
          transform: [
            {
              scale: interpolations[index].scale,
            },
          ],
        };
        const opacityStyle = {
          opacity: interpolations[index].opacity,
        };
        return (
          <MapView.Marker key={index} coordinate={marker.coordinate}>
            <Animated.View style={[styles.markerWrap, opacityStyle]}>
              <Animated.View style={[styles.ring, scaleStyle]}/>
              <View style={styles.marker}/> 
            </Animated.View>
          </MapView.Marker>
        );
      })}
    </MapView>
    <Animated.ScrollView
      horizontal={true}
      scrollEventThrottle={1}
      pagingEnabled={true} 
      showsHorizontalScrollIndicator={false}
      snapToInterval={CARD_WIDTH}
      onScroll={Animated.event(
        [
          {
            nativeEvent: {
              contentOffset: {
                x: this.animation,
              },
            },
          },
        ],
        { useNativeDriver: true }
      )}
      style={styles.scrollView}
      contentContainerStyle={styles.endPadding}
    >
      {this.state.markers.map((marker, index) => {
        <View style={styles.card} key={index}>
          <Image
            source={marker.image}
            style={styles.cardImage}
            resizeMode="cover"
          />
          <View style={styles.textContent}>
            <Text numberOfLines={1} style={styles.cardtitle}>{marker.title}</Text>
            <Text numberOfLines={1} style={styles.cardDescription}>
              {marker.description}
            </Text>
          </View>
        </View>
      })}
    </Animated.ScrollView>
    {/* <TouchableOpacity onPress={this.getLocationHandler} style={styles.iconContainer}>
      <Icon name="md-locate" size={30} color="blue"/>
    </TouchableOpacity> */}
  </View>
);

Для таблицы стилей:

const styles = StyleSheet.create({
 container: {
  alignItems: 'center',
 },
 map: {
  height: '100%',
  width: '100%'
 },
 iconContainer: {
  position: 'absolute',
  top: 60,
  right: 15,
  zIndex: 1
 },
//--- Style for Marker -----//
markerWrap: {
  alignItems: 'center',
  justifyContent: 'center',
},
marker: {
  width: 8,
  height: 8,
  borderRadius: 4,
  backgroundColor: "rgba(130,4,150, 0.9)",
},
ring: {
  width: 24,
  height: 24,
  borderRadius: 12,
  backgroundColor: "rgba(130,4,150, 0.3)",
  position: "absolute",
  borderWidth: 1,
  borderColor: "rgba(130,4,150, 0.5)",
},
scrollView: {
  position: "absolute",
  bottom: 30,
  left: 0,
  right: 0,
  paddingVertical: 10,
},
endPadding: {
  paddingRight: width - CARD_WIDTH,
},
card: {
  padding: 10,
  elevation: 2,
  backgroundColor: "#FFF",
  marginHorizontal: 10,
  shadowColor: "#000",
  shadowRadius: 5,
  shadowOpacity: 0.3,
  shadowOffset: { x: 2, y: -2 },
  height: CARD_HEIGHT,
  width: CARD_WIDTH,
  overflow: "hidden",
},
cardImage: {
  flex: 3,
  width: "100%",
  height: "100%",
  alignSelf: "center",
},
textContent: {
  flex: 1,
},
cardTitle: {
  fontSize: 12,
  marginTop: 5,
  fontWeight: "bold",
},
cardDescription: {
  fontSize: 12,
  color: "#444",
}
})

1 Ответ

0 голосов
/ 08 мая 2019

Используйте эти стили:

container: {
    flex: 1
},
map: {
    flex: 1,
    ...StyleSheet.absoluteFillObject,
    top: 0, left: 0, right: 0, bottom: -25
},
scrollView: { // Or for a simple View, Or Card
    // ...
    position: 'absolute',
    bottom: 0,
    zIndex: 100,
}
...