maps icon indicating copy to clipboard operation
maps copied to clipboard

[Bug]: MapView onPress doesn't fire through VectorSource Layer

Open RussMax783 opened this issue 7 months ago • 0 comments

Mapbox Implementation

Mapbox

Mapbox Version

10.1.39

React Native Version

0.79.2

Platform

iOS

@rnmapbox/maps version

10.16.*

Standalone component to reproduce

import React from 'react';
import {MapView, Camera, VectorSource, LineLayer} from '@rnmapbox/maps';
import {View} from 'react-native';
const styles = {
  mapView: {flex: 1},
  lineLayer: {
    lineCap: 'round',
    lineJoin: 'round',
    lineOpacity: 0.6,
    lineColor: 'rgb(255,0, 109)',
    lineWidth: 2.0,
  },
};

const defaultCameraSettings = {
  centerCoordinate: [-87.622088, 41.878781],
  zoomLevel: 10,
};


const tileUrlTemplates = [
  'https://tiles.mapillary.com/maps/vtp/mly1_public/2/{z}/{x}/{y}?access_token=MLY|4142433049200173|72206abe5035850d6743b23a49c41333'.replaceAll(
    '|',
    '%7C',
  ),
];

function App() {
  return (
    <View
      style={{
        flex: 1,
      }}>
      <MapView
        style={styles.mapView}
        onPress={() => console.log('MapView onPress')}>
        <Camera defaultSettings={defaultCameraSettings} />
        <VectorSource id="mapillary" tileUrlTemplates={tileUrlTemplates}>
          <LineLayer
            id="mapillary-lines"
            sourceLayerID="sequence"
            style={styles.lineLayer}
          />
        </VectorSource>
      </MapView>
    </View>
  );
}

export default App;

Observed behavior and steps to reproduce

When you press the map on a LineLayer the MapView onPress event should fire but it doesn't.

Expected behavior

The mapView on press event should fire

Notes / preliminary analysis

Tracked the bug down to RNMBXVectorSourceComponentView.mm to lines about 126 -128

if (hasPressListener != nil) {
        _view.hasPressListener = hasPressListener;
    }

hasPressListener is always evaluated to true.

the fix is to cast (if thats the right word) the hasPressListener to a boolean

if (hasPressListener != nil) {
        _view.hasPressListener = [hasPressListener boolValue];
}

Additional links and references

Here is a temp patch for anyone needing it

diff --git a/node_modules/@rnmapbox/maps/ios/RNMBX/RNMBXVectorSourceComponentView.mm b/node_modules/@rnmapbox/maps/ios/RNMBX/RNMBXVectorSourceComponentView.mm
index 6fa2cb0..332701b 100644
--- a/node_modules/@rnmapbox/maps/ios/RNMBX/RNMBXVectorSourceComponentView.mm
+++ b/node_modules/@rnmapbox/maps/ios/RNMBX/RNMBXVectorSourceComponentView.mm
@@ -124,7 +124,7 @@ using namespace facebook::react;
     }
     id hasPressListener = RNMBXConvertFollyDynamicToId(newProps.hasPressListener);
     if (hasPressListener != nil) {
-        _view.hasPressListener = hasPressListener;
+        _view.hasPressListener = [hasPressListener boolValue];
     }
     id hitbox = RNMBXConvertFollyDynamicToId(newProps.hitbox);
     if (hitbox != nil) {

RussMax783 avatar Jun 03 '25 18:06 RussMax783