2017-04-15 21 views
0

私はこの試みた:ネイティブマップのコールアウトに反応するリンク(URL)を追加するにはどうすればよいですか?

<MapView.Marker id={marker.id} 
       coordinate={marker.coordinates} 
       title={marker.title}> 
       <MapView.Callout style={styles.callout} > 
     <Text style={styles.link} onPress={this.openUrl.bind(this)}> 
        {this.props.marker.link} 
     </Text> 
    </MapView.Callout> 
</MapView.Marker> 

をしかし、OpenURLの機能を呼び出すことはありません。

答えて

0

テキストは、たonPressコールバックを含んMapView.CalloutテキストからたonPressを移動しません。

<MapView.Callout 
     onPress={this.openUrl.bind(this)} 
     style={styles.callout} 
     > 
      <Text style={styles.link}> 
       {this.props.marker.link} 
      </Text> 
</MapView.Callout> 

更新: 複数のリンクを持つために、あなたはカスタムコールアウトを使用することができます。コールアウトからたonPressを削除し、吹き出しにクリック可能な子を追加:

 <MapView.Callout 
     style={styles.callout} 
     > 
     <TouchableOpacity 
      onPress={()=>{this.openUrl(this.props.marker.link1)}} 
     > 
      <Text style={styles.link}> 
      {this.props.marker.link1} 
      </Text> 
     </TouchableOpacity> 
     <TouchableOpacity 
      onPress={()=>{this.openUrl(this.props.marker.link2)}} 
     > 
      <Text style={styles.link}> 
      {this.props.marker.link2} 
      </Text> 
     </TouchableOpacity> 
     </MapView.Callout> 
+0

しかし、その場合には、私は吹き出しに複数のクリック可能なリンクを追加するためにコールアウト –

+0

で複数のリンクを作成することはできません、あなたがたonPressを使用する必要があります(更新された答えを見てください)。 –

関連する問題