maps icon indicating copy to clipboard operation
maps copied to clipboard

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

Open vaishnavi-techp opened this issue 1 year ago • 23 comments

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

vaishnavi-techp avatar Dec 05 '24 16:12 vaishnavi-techp

+1

youtipie avatar Dec 09 '24 16:12 youtipie

I am facing the same issue.

bitkraft-ssheikh avatar Dec 12 '24 04:12 bitkraft-ssheikh

Mee too

jayjo34 avatar Dec 19 '24 06:12 jayjo34

I am running into this issue as well. Is there a workaround available ?

prashantsail avatar Dec 23 '24 06:12 prashantsail

I am facing same issue

yashp1998 avatar Dec 23 '24 06:12 yashp1998

Also have this issue. Any solutions?

MykytaShchukin avatar Jan 09 '25 11:01 MykytaShchukin

same issue for me. Any solutions??

smartmedev avatar Jan 17 '25 22:01 smartmedev

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

Pakile avatar Feb 03 '25 03:02 Pakile

+1

cyburns avatar Feb 03 '25 20:02 cyburns

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

txnnr avatar Feb 06 '25 02:02 txnnr

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

Pakile avatar Feb 06 '25 02:02 Pakile

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

stalteri avatar Feb 12 '25 15:02 stalteri

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"

mysport12 avatar Feb 15 '25 19:02 mysport12

Same issue on 10.1.37

vigor-13 avatar Mar 31 '25 02:03 vigor-13

Same issue on 10.1.37

SsankQ avatar Mar 31 '25 02:03 SsankQ

Same issue on 10.1.37

ShahilMangroliya avatar Mar 31 '25 05:03 ShahilMangroliya

Any update on this issue?

cyburns avatar Apr 16 '25 19:04 cyburns

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

ShahilMangroliya avatar Apr 17 '25 04:04 ShahilMangroliya

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

[
  "@rnmapbox/maps",
  {
      "RNMapboxMapsVersion": "11.8.0"
  }
]

vegtelenseg avatar Apr 19 '25 04:04 vegtelenseg

Any workaround found here??

deathook007 avatar Apr 28 '25 09:04 deathook007

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

dominikjambor avatar Apr 28 '25 10:04 dominikjambor

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

Thanks in advance.

udaysagartammina avatar Aug 18 '25 06:08 udaysagartammina

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

ourdudekyle avatar Aug 18 '25 21:08 ourdudekyle