maps icon indicating copy to clipboard operation
maps copied to clipboard

[Bug]: [Android] [newArch] MarkerView Pressable onPress does not work

Open cixio opened this issue 10 months ago • 6 comments

Mapbox Implementation

Mapbox

Mapbox Version

default

React Native Version

0.79.0

Platform

Android

@rnmapbox/maps version

10.1.38

Standalone component to reproduce

import React from 'react';
import { Pressable, View } from 'react-native';
import Mapbox from '@rnmapbox/maps';

function App() {

  return (
      <Mapbox.MapView
        style={{ flex: 1 }}
        onPress={()=>{console.log('mapview press!');}}
        onLongPress={()=>{console.log('mapview longpress');}}
      >	
        <Mapbox.Camera
          centerCoordinate={[0, 0]}
          zoomLevel={3}
        />
        
        <Mapbox.MarkerView
          id={"test"}
          coordinate={[0,0]}
          anchor={{ x: 0.5, y: 0.5 }}
          allowOverlap={true}
        >
          <Pressable 
            onPress={()=>{console.log('press marker!');}}>
            <View style={{ backgroundColor: 'green', width: 50, height: 50}}>
            </View>
          </Pressable>
        </Mapbox.MarkerView>
      </Mapbox.MapView>
  );
}

export default App;

Observed behavior and steps to reproduce

MarkerView onPress does not work at all MapView onLongPress does only work directly after startup once

Expected behavior

MarkerView onPress should work everytime pressed MapView onLongPress should work everytime long pressed

Notes / preliminary analysis

only on android new arch, no issue on iOS, no issue on old arch

Additional links and references

No response

cixio avatar Apr 08 '25 22:04 cixio

@cixio are you able to run v10.1.38 mapbox on v0.79 android?

This onPress issue is very annoying. For a temporary fix i imported Pressable from the gesture library

import { Pressable } from 'react-native-gesture-handler';

msaqlain avatar Apr 10 '25 07:04 msaqlain

@cixio are you able to run v10.1.38 mapbox on v0.79 android?

Sure, works great with the patch from here: https://github.com/rnmapbox/maps/issues/3753#issuecomment-2682660143 , but same bug.

This onPress issue is very annoying. For a temporary fix i imported Pressable from the gesture library

import { Pressable } from 'react-native-gesture-handler';

Thank you, this helped for the MarkerViews! As I am using react navigation I had to implement GestureHandlerRootView on my App.tsx.

Now I am facing some other problems with buttons I placed on top of the mapview... I wish I could get to the bottom of the real problem/bug, but I don't understand anything about native Android programming.

cixio avatar Apr 10 '25 14:04 cixio

MapView onLongPress

pointAnnotations.getAndClearAnnotationDragged() is always true after first longpress:

https://github.com/rnmapbox/maps/blob/10a2b19c7f398a33a7f105572b095bc692d531c8/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/RNMBXMapView.kt#L784C1-L786C10

cixio avatar Apr 14 '25 00:04 cixio

MarkerView onPress

<MarkerView>
<Pressable 
  onPress={()=> { console.log('press'); }}		
  onPressIn={() => { console.log('pressIN'); }}
  onPressIn={() => { console.log('pressIN'); }}
  onPressOut={() => { console.log('pressOUT'); }}
  onLongPress={() => { console.log('longPress'); }}
>
...
  • onPress and onLongPress will both never be executed
  • after onPressIn onPressOut will be executed immediately (without doing a pressOut)

so I will use onPressIn as hack to fix it until the repo will be fixed

cixio avatar Apr 15 '25 18:04 cixio