Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: LongPress on marker propagates to map LongPress #3346

Open
Jzuni97 opened this issue Jan 29, 2024 · 0 comments
Open

[Bug]: LongPress on marker propagates to map LongPress #3346

Jzuni97 opened this issue Jan 29, 2024 · 0 comments
Labels
bug 🪲 Something isn't working

Comments

@Jzuni97
Copy link

Jzuni97 commented Jan 29, 2024

Mapbox Implementation

Mapbox

Mapbox Version

11.0.0

Platform

iOS

@rnmapbox/maps version

10.1.8

Standalone component to reproduce

import React, { useMemo, useState } from "react";
import { Pressable, View } from "react-native";
import { Camera, MapView, MarkerView } from "@rnmapbox/maps";

const Map = () => {
  const [selectedMarkerId, setSelectedMarkerId] = useState(0);

  const markers = useMemo(
    () => [
      {
        id: 0,
        lat: 41.393042,
        lng: 2.1848,
      },
      {
        id: 1,
        lat: 41.393242,
        lng: 2.1853,
      },
      {
        id: 2,
        lat: 41.392747,
        lng: 2.185167,
      },
    ],
    [],
  );

  return (
    <MapView
      style={{ flex: 1 }}
      onLongPress={(event) => console.log('Map Long Press Fired...')}
    >
      <Camera centerCoordinate={[2.1848, 41.393042]} zoomLevel={14} />
      {markers.map((marker) => (
        <MarkerView key={marker.id} coordinate={[marker.lng, marker.lat]}>
          <Pressable onPress={() => setSelectedMarkerId(marker.id)}>
            <View
              style={{
                height: 30,
                width: 30,
                backgroundColor:
                  marker.id === selectedMarkerId ? "red" : "blue",
              }}
            />
          </Pressable>
        </MarkerView>
      ))}
    </MapView>
  );
};

export default Map;

Observed behavior and steps to reproduce

I am trying to handle a long press event on the marker, but the map also has a long press function that handles initiating a task. Unfortunately, when the marker is pressed, both long press events are fired (marker & map). I noticed a similar bug report earlier on Android but was closed due to it not being reproducible. Not sure if it was fixed in Android but iOS seems to cause this issue.

Expected behavior

I would like the long press to be fired only on the marker and not propagate to the map long press event.

Notes / preliminary analysis

I tried adding e.stopPropagation() but didn't work as planned and saw a comment stating it's not currently supported but maybe planned in the future. See second link in additional links and references.

Additional links and references

  • Noticed a similar bug report on android but this is happening on iOS: #2598
  • Plan for event propagation handling: #2836
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant