区域更改后,React Native Maps自定义标记不可触摸

时间:2016-11-12 21:48:48

标签: reactjs react-native

我在React Native Maps中使用自定义标记。在初始加载时,触摸标记将显示标记的标注(标题和描述)。但是,将地图拖动到新区域后,标记将不再可触摸。要在更改区域后显示标记的标题和说明,用户必须完全点击标记坐标。

拖动地图时,标记图像会闪烁进出。我认为这可能与他们变得无法接触有关。我怎么能阻止这个?

<MapView
  style={styles.homeMapView}
  region={this.state.currentLocation}
  onRegionChange={this.onRegionChange}
  showsUserLocation={true}
  onPress={(evt) => console.log(evt.nativeEvent.coordinate)}
>
  {this.state.nearbyLocations.map((marker, key) => (
    <MapView.Marker
      key={marker.id}
      coordinate={marker.coordinate}
      title={marker.title}
      description={marker.description}
      onPress={(evt) => console.log('pressed ', evt)}
      image={require('../Public/existingPins.png')}
      centerOffset={{x: 0, y: -20}}
    />
  ))}
</MapView>

修改

在地图区域更改后,似乎标记实际上是可触摸的。即使地图区域发生变化,标记的onPress功能仍然会在每次触摸标记时记录控制台日志。在稍微阅读React Native Maps docs之后,看起来可以通过触摸调用showCallout的区域是唯一缩小的部分。如果使用自定义标记,则此可触摸区域仅缩小。

1 个答案:

答案 0 :(得分:0)

您是否尝试使用onSelect prop而不是onPress prop?