Skip to content

Commit b9aaa20

Browse files
committed
feat: add onMapLongPress
1 parent 4bd8e47 commit b9aaa20

File tree

6 files changed

+37
-0
lines changed

6 files changed

+37
-0
lines changed

android/src/main/java/com/rngooglemapsplus/GoogleMapsViewImpl.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class GoogleMapsViewImpl(
5858
GoogleMap.OnCameraMoveListener,
5959
GoogleMap.OnCameraIdleListener,
6060
GoogleMap.OnMapClickListener,
61+
GoogleMap.OnMapLongClickListener,
6162
GoogleMap.OnMarkerClickListener,
6263
GoogleMap.OnPolylineClickListener,
6364
GoogleMap.OnPolygonClickListener,
@@ -127,6 +128,7 @@ class GoogleMapsViewImpl(
127128
googleMap?.setOnPolygonClickListener(this@GoogleMapsViewImpl)
128129
googleMap?.setOnCircleClickListener(this@GoogleMapsViewImpl)
129130
googleMap?.setOnMapClickListener(this@GoogleMapsViewImpl)
131+
googleMap?.setOnMapLongClickListener(this@GoogleMapsViewImpl)
130132
googleMap?.setOnMarkerDragListener(this@GoogleMapsViewImpl)
131133
onMapLoaded?.invoke(true)
132134
}
@@ -381,6 +383,7 @@ class GoogleMapsViewImpl(
381383
var onLocationUpdate: ((RNLocation) -> Unit)? = null
382384
var onLocationError: ((RNLocationErrorCode) -> Unit)? = null
383385
var onMapPress: ((RNLatLng) -> Unit)? = null
386+
var onMapLongPress: ((RNLatLng) -> Unit)? = null
384387
var onMarkerPress: ((String?) -> Unit)? = null
385388
var onPolylinePress: ((String?) -> Unit)? = null
386389
var onPolygonPress: ((String?) -> Unit)? = null
@@ -874,6 +877,7 @@ class GoogleMapsViewImpl(
874877
setOnPolygonClickListener(null)
875878
setOnCircleClickListener(null)
876879
setOnMapClickListener(null)
880+
setOnMapLongClickListener(null)
877881
setOnMarkerDragListener(null)
878882
}
879883
googleMap = null
@@ -953,6 +957,12 @@ class GoogleMapsViewImpl(
953957
)
954958
}
955959

960+
override fun onMapLongClick(coordinates: LatLng) {
961+
onMapLongPress?.invoke(
962+
coordinates.toRnLatLng(),
963+
)
964+
}
965+
956966
override fun onMarkerDragStart(marker: Marker) {
957967
onMarkerDragStart?.invoke(
958968
marker.tag?.toString(),

android/src/main/java/com/rngooglemapsplus/RNGoogleMapsPlusView.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,11 @@ class RNGoogleMapsPlusView(
301301
view.onMapPress = cb
302302
}
303303

304+
override var onMapLongPress: ((RNLatLng) -> Unit)? = null
305+
set(cb) {
306+
view.onMapLongPress = cb
307+
}
308+
304309
override var onMarkerPress: ((String?) -> Unit)? = null
305310
set(cb) {
306311
view.onMarkerPress = cb

example/src/components/MapWrapper.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ export default function MapWrapper(props: Props) {
129129
f: (c: RNLatLng) => console.log('Map press:', c),
130130
}
131131
)}
132+
onMapLongPress={callback(
133+
props.onMapLongPress ?? {
134+
f: (c: RNLatLng) => console.log('Map long press:', c),
135+
}
136+
)}
132137
onMarkerPress={callback(
133138
props.onMarkerPress ?? {
134139
f: (id: string | undefined) => console.log('Marker press:', id),

ios/GoogleMapViewImpl.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ GMSIndoorDisplayDelegate {
258258
var onLocationUpdate: ((RNLocation) -> Void)?
259259
var onLocationError: ((_ error: RNLocationErrorCode) -> Void)?
260260
var onMapPress: ((RNLatLng) -> Void)?
261+
var onMapLongPress: ((RNLatLng) -> Void)?
261262
var onMarkerPress: ((String?) -> Void)?
262263
var onPolylinePress: ((String?) -> Void)?
263264
var onPolygonPress: ((String?) -> Void)?
@@ -719,6 +720,17 @@ GMSIndoorDisplayDelegate {
719720
}
720721
}
721722

723+
func mapView(
724+
_ mapView: GMSMapView,
725+
didLongPressAt coordinate: CLLocationCoordinate2D
726+
) {
727+
onMain {
728+
self.onMapLongPress?(
729+
coordinate.toRNLatLng(),
730+
)
731+
}
732+
}
733+
722734
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
723735
onMain {
724736
mapView.selectedMarker = marker

ios/RNGoogleMapsPlusView.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ final class RNGoogleMapsPlusView: HybridRNGoogleMapsPlusViewSpec {
318318
didSet { impl.onMapPress = onMapPress }
319319
}
320320
@MainActor
321+
var onMapLongPress: ((RNLatLng) -> Void)? {
322+
didSet { impl.onMapLongPress = onMapLongPress }
323+
}
324+
@MainActor
321325
var onMarkerPress: ((String?) -> Void)? {
322326
didSet { impl.onMarkerPress = onMarkerPress }
323327
}

src/RNGoogleMapsPlusView.nitro.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export interface RNGoogleMapsPlusViewProps extends HybridViewProps {
5555
onLocationUpdate?: (location: RNLocation) => void;
5656
onLocationError?: (error: RNLocationErrorCode) => void;
5757
onMapPress?: (coordinate: RNLatLng) => void;
58+
onMapLongPress?: (coordinate: RNLatLng) => void;
5859
onMarkerPress?: (id?: string | undefined) => void;
5960
onPolylinePress?: (id?: string | undefined) => void;
6061
onPolygonPress?: (id?: string | undefined) => void;

0 commit comments

Comments
 (0)