简体   繁体   English

TouchableOpacity onLongPress 不适用于 android

[英]TouchableOpacity onLongPress not working on android

i have been trying to use a TouchableOpacity inside a react-native-maps Marker heres the code:我一直在试图用一个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>

now the problem is this works fine on ios both the onPress and onLongPress events get invoked but on android none of them gets called this is so confusing and i dont know why.现在的问题是这在 ios 上运行良好, onPressonLongPress事件都被调用,但在 android 上没有一个被调用,这太令人困惑了,我不知道为什么。 is there something i am missing here or something i should be adding?有什么我在这里遗漏的或者我应该添加的东西吗?

and also i am importing ToucahbleOpacity from react-native-gesture-handler .而且我正在从react-native-gesture-handler导入ToucahbleOpacity i tried importing it from react-native but that just doesnt work on both platforms我尝试从react-native导入它,但这在两个平台上都不起作用

android will have limitations here. android在这里会有限制。 Android renders the markers and the callout as bitmaps directly, and they don't have interactivity. Android 将标记和标注直接呈现为位图,并且它们没有交互性。 So as far as I know you you can not所以据我所知你不能

use long press functionality inside marker all you can use is onPress functionality which can be called inside marker component在标记内使用长按功能,您可以使用的是 onPress 功能,可以在标记组件内调用

<Marker onPress={() => {console.log('in')}}>
  <View>
    <TextWithStyle style={styles.markerText}>{'Home'}</TextWithStyle>               
  </View>
</Marker>

Or if this is not helpful.或者如果这没有帮助。 Checkout this answere if that helps Marker click event on react native maps not working in react ios如果这有助于反应原生地图上的标记单击事件在反应 ios 中不起作用,请查看此答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM