我目前正在尝试在我的应用程序中,当我按下卡片上的X按钮时关闭我的callout。
我的代码如下。**关闭卡片的函数**
最后,在同一文件中,此组件调用了取消卡的函数:
我的代码如下。**关闭卡片的函数**
unsetCard = id => {
this.setState({
...this.state,
showCard: false,
});
this.markers.hideCallout();
if (this.state.keyboard) {
Keyboard.dismiss();
}
};
这是我的地图视图代码,我使用RN聚合。
<MapView
//
mapRef={ref => (this.myMapRef = ref)}
//
onPress={this.unsetCard}>
{this.props.data.map(marker => (
<Marker
key={marker.id}
ref={ref => (this.markers = ref)}
//
}>
<Callout
//
}}>
<CustomCallout title={marker.t} />
</Callout>
</Marker>
))}
</MapView>
最后,在同一文件中,此组件调用了取消卡的函数:
<CustomCardWithImage
close={() => this.unsetCard(this.state.cardInfo.id)}
/>
我希望有人告诉我如何使用ref来引用标记,因为尽管我尝试了很多次,但它并没有起作用。
提前致谢,