【问题标题】:TouchableOpacity onLongPress not working on androidTouchableOpacity onLongPress 在安卓上不起作用
【发布时间】:2019-11-22 19:09:44
【问题描述】:

我一直在尝试在 react-native-maps Marker 中使用 TouchableOpacity 代码:

<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>

现在的问题是这在 ios 上运行良好,onPressonLongPress 事件都被调用,但在 android 上它们都没有被调用,这太令人困惑了,我不知道为什么。这里有什么我遗漏的或者我应该添加的东西吗?

而且我正在从react-native-gesture-handler 导入ToucahbleOpacity。我尝试从react-native 导入它,但这在两个平台上都不起作用

【问题讨论】:

    标签: android react-native react-native-maps long-press touchableopacity


    【解决方案1】:

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-07
      • 2013-01-23
      • 1970-01-01
      • 2016-08-26
      相关资源
      最近更新 更多