React-native Airbnb-Maps: How do I render a button inside the airbnb maps pop-up box?

徘徊边缘 提交于 2020-01-03 02:48:21

问题


I am trying to render a button which I can use to redirect to another page within the description page (the pop-up-box if you select a marker) using AirBnb maps (using MapView.Markers). I am not sure how to achieve this.

Currently my markers look as follow:

const markers = [{
  longitude: 8.545592,
  latitude: 47.366465,
  description: "Bike 1",
  title: "Bike 1"
},
{
  longitude: 8.545892,
  latitude: 47.366365,
  description: "Bike 2",
  title: "Bike 2"
}
];

Whenever I try to input JSX into a text, I get a NSMutableDictionary cannot be converted to NSString error. (When I do this:

const markers = [{
  longitude: 8.545592,
  latitude: 47.366465,
  description: <Text>Bike1</Text>, //"Bike 1", //<Text> Bike1 </Text>
  title: "Bike 1"
},
{
  longitude: 8.545892,
  latitude: 47.366365,
  description: "Bike 2",
  title: "Bike 2"
}
];

回答1:


For more than just text, what you should do is define a custom Callout instead of using description prop. For example:

<MapView.Marker
  coordinate={{longitude: marker.longitude, latitude: marker.latitude}}
  title={marker.title}
>
  <MapView.Callout>
    <View style={styles.callout}>
      <Button title='Click Me!' onPress={() => console.log('Clicked')} />
    </View>
  </MapView.Callout>
</MapView.Marker>


来源:https://stackoverflow.com/questions/44475332/react-native-airbnb-maps-how-do-i-render-a-button-inside-the-airbnb-maps-pop-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!