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]: Camera manipulation not working within onLongPress #2738

Open
michalpazur opened this issue Mar 24, 2023 · 2 comments
Open

[Bug]: Camera manipulation not working within onLongPress #2738

michalpazur opened this issue Mar 24, 2023 · 2 comments

Comments

@michalpazur
Copy link

Mapbox Implementation

Mapbox

Mapbox Version

default

Platform

iOS, Android

@rnmapbox/maps version

10.0.0-rc.1

Standalone component to reproduce

import MapboxGL, { Camera } from "@rnmapbox/maps";
import React, { useRef } from "react";
import { StyleSheet, View } from "react-native";

const MapView = MapboxGL.MapView;

const Map: React.FC = () => {
  const mapCamera = useRef<Camera>(null);

  const flyToCoordinates = async (coordinates: GeoJSON.Position) => {
    mapCamera.current?.flyTo(coordinates);
  };

  const onLongPress = (feature: GeoJSON.Feature) => {
    const point = feature as GeoJSON.Feature<GeoJSON.Point>;
    const coordinates = point.geometry.coordinates;
    flyToCoordinates(coordinates);
  };

  return (
    <View style={StyleSheet.absoluteFillObject}>
      <MapView onLongPress={onLongPress} style={{ flex: 1 }}>
        <Camera
          centerCoordinate={[-0.15, 51.51]}
          zoomLevel={16}
          maxZoomLevel={18}
          ref={mapCamera}
        />
      </MapView>
    </View>
  );
};

export default Map;

Observed behavior and steps to reproduce

  • Long press with finger on a map
  • Map doesn't pan to place where finger was held despite flyTo having been called
RPReplay_Final1679650585.MP4

Expected behavior

Map should pan to the place where user's finger was held.

Notes / preliminary analysis

  • This code works if flyTo is called inside onPress callback.
  • This affects all Camera methods, including flyTo, panTo, setCamera.
  • It seems to be caused by longPress event firing before user takes their finger off the screen.

Additional links and references

No response

@mfazekas
Copy link
Contributor

@michalpazur thanks much for the report the issue is that we report false from longClick handler.

val screenPoint = mMap?.pixelForCoordinate(point)
if (screenPoint != null) {
val event = MapClickEvent(_this, LatLng(point), screenPoint, EventTypes.MAP_LONG_CLICK)
mManager.handleEvent(event)
}
return false

https://docs.mapbox.com/android/maps/api/10.12.1/mapbox-maps-android/com.mapbox.maps.plugin.gestures/-on-map-long-click-listener/on-map-long-click.html

One solution is to always return true if there is a longPress javascript handler, another one is to interrupt the gesture handler once the javascript code was run.

val gestureManager = map.gestures.getGesturesManager()
gestureManager.moveGestureDetector.interrupt()

@cometman
Copy link

Having the same issue. Works when using onPress but onLongPress does not allow me to setCamera. I tried returning true from all my handlers but did not resolve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants