Skip to content

Commit

Permalink
add iosLongClickDuration paramater
Browse files Browse the repository at this point in the history
  • Loading branch information
m0nac0 committed Dec 1, 2023
1 parent 0bf3260 commit 287e661
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions example/lib/custom_marker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class CustomMarkerState extends State<CustomMarker> {
onStyleLoadedCallback: _onStyleLoadedCallback,
initialCameraPosition:
const CameraPosition(target: LatLng(35.0, 135.0), zoom: 5),
iosLongClickDuration: const Duration(milliseconds: 200),
),
IgnorePointer(
ignoring: true,
Expand Down
14 changes: 13 additions & 1 deletion ios/Classes/MapboxMapController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
{
longPress.require(toFail: recognizer)
}
mapView.addGestureRecognizer(longPress)
var longPressRecognizerAdded = false

if let args = args as? [String: Any] {

Convert.interpretMapboxMapOptions(options: args["options"], delegate: self)
if let initialCameraPosition = args["initialCameraPosition"] as? [String: Any],
let camera = MGLMapCamera.fromDict(initialCameraPosition, mapView: mapView),
Expand All @@ -98,6 +99,12 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
if let enabled = args["dragEnabled"] as? Bool {
dragEnabled = enabled
}

if let iosLongClickDurationMilliseconds = args["iosLongClickDurationMilliseconds"] as? Int {
longPress.minimumPressDuration = TimeInterval(iosLongClickDurationMilliseconds) / 1000
mapView.addGestureRecognizer(longPress)
longPressRecognizerAdded = true
}
}
if dragEnabled {
let pan = UIPanGestureRecognizer(
Expand All @@ -107,6 +114,11 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
pan.delegate = self
mapView.addGestureRecognizer(pan)
}

if(!longPressRecognizerAdded) {
mapView.addGestureRecognizer(longPress)
longPressRecognizerAdded = true
}
}

func gestureRecognizer(
Expand Down
7 changes: 7 additions & 0 deletions lib/src/maplibre_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class MaplibreMap extends StatefulWidget {
this.compassViewMargins,
this.attributionButtonPosition = AttributionButtonPosition.BottomRight,
this.attributionButtonMargins,
this.iosLongClickDuration,
this.onMapClick,
this.onUserLocationUpdated,
this.onMapLongClick,
Expand Down Expand Up @@ -88,6 +89,11 @@ class MaplibreMap extends StatefulWidget {
/// The initial position of the map's camera.
final CameraPosition initialCameraPosition;

/// How long a user has to click the map **on iOS** until a long click is registered.
/// Has no effect on web or Android. Can not be changed at runtime, only the initial value is used.
/// If null, the default value of the native MapLibre library / of the OS is used.
final Duration? iosLongClickDuration;

/// True if the map should show a compass when rotated.
final bool compassEnabled;

Expand Down Expand Up @@ -260,6 +266,7 @@ class _MaplibreMapState extends State<MaplibreMap> {
'options': _MaplibreMapOptions.fromWidget(widget).toMap(),
//'onAttributionClickOverride': widget.onAttributionClick != null,
'dragEnabled': widget.dragEnabled,
if(widget.iosLongClickDuration != null) 'iosLongClickDurationMilliseconds': widget.iosLongClickDuration!.inMilliseconds,
};
return _maplibreGlPlatform.buildView(
creationParams, onPlatformViewCreated, widget.gestureRecognizers);
Expand Down

0 comments on commit 287e661

Please sign in to comment.