Skip to content

[Bug]: On Android, onLongPress function is working only once(initial render) #3715

Closed

Description

@vaishnavi-techp

Mapbox Implementation

Mapbox

Mapbox Version

10.1.32

React Native Version

0.74.5

Platform

Android

@rnmapbox/maps version

10.0.0-beta.32

Standalone component to reproduce

import React from 'react';
import {
  MapView,
  ShapeSource,
  LineLayer,
  Camera,
} from '@rnmapbox/maps';

const aLine = {
  type: 'LineString',
  coordinates: [
    [-74.00597, 40.71427],
    [-74.00697, 40.71527],
  ],
};

class BugReportExample extends React.Component {
  render() {
    return (
      <MapView style={{flex: 1}}   onLongPress={() => console.log("long press")}>
        <Camera centerCoordinate={[-74.00597, 40.71427]} zoomLevel={14} />
        <ShapeSource id="idStreetLayer" shape={aLine}>
          <LineLayer id="idStreetLayer" />
        </ShapeSource>
      </MapView>
    );
  }
}

Observed behavior and steps to reproduce

onLongPress is triggered only once (during the initial render) on Android, but works as expected on iOS.

Expected behavior

onLongPress should be triggered whenever the user performs a long press on the map.

Notes / preliminary analysis

No response

Additional links and references

No response

Activity

  1. Pakile commented on Feb 3, 2025

    @Pakile

    Also have this issue. Downgrade to version 10.1.31 to fix this issue

  2. cyburns commented on Feb 3, 2025

    @cyburns

    +1

  3. txnnr commented on Feb 6, 2025

    @txnnr

    I have this issue as well and downgrading to 10.1.31 did not solve the issue

  4. Pakile commented on Feb 6, 2025

    @Pakile

    I have this issue as well and downgrading to 10.1.31 did not solve the issue

    did you remove the ^?
    fixed for me: "@rnmapbox/maps": "10.1.31",

  5. stalteri commented on Feb 12, 2025

    @stalteri

    Same issue on 10.1.33. An older version (I don’t remember exactly which one) works well.

  6. mysport12 commented on Feb 15, 2025

    @mysport12
    Contributor

    Seems like the issue was introduced when the android SDK version was bumped prior to 10.1.32 being released. Reverting the default sdk version via a fork/patch is a workaround while still using the latest release of rnmapbox

    android/build.gradle:

    • def defaultMapboxMapsVersion = "10.18.4"
    • def defaultMapboxMapsVersion = "10.18.0"
  7. added a commit that references this issue on Feb 17, 2025
  8. vigor-13 commented on Mar 31, 2025

    @vigor-13

    Same issue on 10.1.37

  9. SsankQ commented on Mar 31, 2025

    @SsankQ

    Same issue on 10.1.37

  10. ShahilMangroliya commented on Mar 31, 2025

    @ShahilMangroliya
    Contributor

    Same issue on 10.1.37

  11. cyburns commented on Apr 16, 2025

    @cyburns

    Any update on this issue?

  12. ShahilMangroliya commented on Apr 17, 2025

    @ShahilMangroliya
    Contributor

    If you change def defaultMapboxMapsVersion = "10.18.0" in build.gradle of the this lib then its working

  13. vegtelenseg commented on Apr 19, 2025

    @vegtelenseg

    Not sure if this will work for others, but I had to use a newer version of mapbox.

    [
      "@rnmapbox/maps",
      {
          "RNMapboxMapsVersion": "11.8.0"
      }
    ]
    
  14. deathook007 commented on Apr 28, 2025

    @deathook007

    Any workaround found here??

  15. dominikjambor commented on Apr 28, 2025

    @dominikjambor

    @deathook007 Here's my complete workaround by locally patching the previously suggested version:

    My rnmapbox version at the moment is: "@rnmapbox/maps": "10.1.37", (this is important for the patch definition)

    1. install patch-package npm i patch-package
    2. create the file patches/@rnmapbox+maps+10.1.37.patch with the following content:`
    diff --git a/node_modules/@rnmapbox/maps/android/build.gradle b/node_modules/@rnmapbox/maps/android/build.gradle
    index dd8e6c6..8f3ff59 100644
    --- a/node_modules/@rnmapbox/maps/android/build.gradle
    +++ b/node_modules/@rnmapbox/maps/android/build.gradle
    @@ -1,5 +1,5 @@
     def defaultMapboxMapsImpl = "mapbox"
    -def defaultMapboxMapsVersion = "10.18.4"
    +def defaultMapboxMapsVersion = "10.18.3"
     
     def safeExtGet(prop, fallback) {
         rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
    
    1. run npx patch-package to patch the rnmapbox package.
    2. add the following script to package.json to make patch-package run in EAS builds: "eas-build-post-install": "patch-package"

    Of course, this does not solve the problem, just downgrades the mapbox version to one that works, while keeping up with other fixes in this repo. At some point downgrading the version will break the library, but for now it works.

    Hope this helps.

  16. udaysagartammina commented on Aug 18, 2025

    @udaysagartammina

    I’m also facing the same issue. Did anyone find a fix for this issue?
    "@rnmapbox/maps": "^10.1.41",

    Thanks in advance.

  17. ourdudekyle commented on Aug 18, 2025

    @ourdudekyle

    Yeah, like others are noticing, this is coming from the Mapbox Android SDK. One work around is to use react-native-gesture-handler and wrap the map view in a gesture detector:

    import { Gesture, GestureDetector } from 'react-native-gesture-handler'
    
      const longPressGesture = Gesture.LongPress()
        .enabled(Platform.OS === "android")
        .runOnJS(true)
        .onStart(async e => {
          if (e) {
            const mapPoint = await mapRef.getCoordinateFromView([e.x, e.y])
    
            if (mapPoint) {
              ... do something with point 
            }
          }
        })
    
      return (
        <GestureDetector gesture={longPressGesture}>
          <View style={{ flex: 1 }} collapsable={false}>
            <Mapbox.MapView
              ref={mapRef}
              onLongPress={Platform.OS === "android" ? undefined : onMapLongPress}
            />
          </View>
        </GestureDetector>
      )
    
  18. rawcomposition commented on Jan 12, 2026

    @rawcomposition

    Just ran into this same issue and was disappointed that there isn't really a solution over a year later 😔

  19. dominikjambor commented on Jan 13, 2026

    @dominikjambor

    @rawcomposition I don't have the problem anymore in 10.2.10 . Which version are you on?

  20. rawcomposition commented on Jan 14, 2026

    @rawcomposition

    You're right! I had forgotten to do a full rebuild after testing the latest version. Long press does indeed work as expected now on 10.2.10!

  21. mfazekas commented on Mar 1, 2026

    @mfazekas
    Contributor

    This appears to be resolved in recent versions. The root cause was in the Mapbox Android SDK (introduced around 10.18.4), and has been fixed in the newer SDK versions that @rnmapbox/maps now depends on.

    Two commenters confirmed it works correctly on 10.2.10, and the current release (10.3.0-beta) uses MapboxMaps 11.18.x which also doesn't have this issue.

    Closing — please reopen if anyone is still seeing this on a current version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🪲

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions