我一直在尝试在TouchableOpacity
react-native-maps
内使用Marker
,此处代码如下:
<MapView.Marker
coordinate={{
latitude: marker.lat,
longitude: marker.lng
}}
anchor={{ x: 0, y: 0 }}
centerOffset={{ x: 0, y: 0 }}
calloutOffset={{ x: 0, y: 0}}
title={marker.title}
description="Sample Description"
>
<TouchableOpacity
onLongPress={() => {console.log("MARKER LONG PRESSED")}}
delayLongPress={1000}
onPress={()=>{console.log("MARKER PRESSED")}}
>
// here i have a custom image for the marker
</TouchableOpacity>
</MapView.Marker>
现在的问题是,在onPress
和onLongPress
事件上都可以在ios上正常运行,但是在android上都没有被调用,这是如此令人困惑,我也不知道为什么。有什么我想念的东西还是应该添加的东西?
我也正在从ToucahbleOpacity
导入react-native-gesture-handler
。我尝试从react-native
导入它,但这在两个平台上均不起作用
答案 0 :(得分:0)
android在这里会有限制。 Android将标记和标注直接渲染为位图,并且它们之间没有交互性。据我所知,您不能
在标记内使用长按功能只能使用onPress功能,该功能可以在标记组件内调用
<Marker onPress={() => {console.log('in')}}>
<View>
<TextWithStyle style={styles.markerText}>{'Home'}</TextWithStyle>
</View>
</Marker>
或者如果这没有帮助。查看此答案是否有帮助 Marker click event on react native maps not working in react ios