Skip to content

Commit d2e0909

Browse files
committed
feat: add onInfoWindowPress
feat: add onInfoWindowClose feat: add onInfoWindowLongPress feat: add onMyLocationPress feat: add onMyLocationButtonPress
1 parent 875e50c commit d2e0909

File tree

6 files changed

+168
-2
lines changed

6 files changed

+168
-2
lines changed

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

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.rngooglemapsplus
22

33
import android.annotation.SuppressLint
44
import android.graphics.Bitmap
5+
import android.location.Location
56
import android.util.Base64
67
import android.util.Size
78
import android.widget.FrameLayout
@@ -67,6 +68,11 @@ class GoogleMapsViewImpl(
6768
GoogleMap.OnCircleClickListener,
6869
GoogleMap.OnMarkerDragListener,
6970
GoogleMap.OnIndoorStateChangeListener,
71+
GoogleMap.OnInfoWindowClickListener,
72+
GoogleMap.OnInfoWindowCloseListener,
73+
GoogleMap.OnInfoWindowLongClickListener,
74+
GoogleMap.OnMyLocationClickListener,
75+
GoogleMap.OnMyLocationButtonClickListener,
7076
LifecycleEventListener {
7177
private var initialized = false
7278
private var destroyed = false
@@ -135,6 +141,11 @@ class GoogleMapsViewImpl(
135141
googleMap?.setOnMapLongClickListener(this@GoogleMapsViewImpl)
136142
googleMap?.setOnPoiClickListener(this@GoogleMapsViewImpl)
137143
googleMap?.setOnMarkerDragListener(this@GoogleMapsViewImpl)
144+
googleMap?.setOnInfoWindowClickListener(this@GoogleMapsViewImpl)
145+
googleMap?.setOnInfoWindowCloseListener(this@GoogleMapsViewImpl)
146+
googleMap?.setOnInfoWindowLongClickListener(this@GoogleMapsViewImpl)
147+
googleMap?.setOnMyLocationClickListener(this@GoogleMapsViewImpl)
148+
googleMap?.setOnMyLocationButtonClickListener(this@GoogleMapsViewImpl)
138149
onMapLoaded?.invoke(true)
139150
}
140151
applyProps()
@@ -406,6 +417,11 @@ class GoogleMapsViewImpl(
406417
var onMarkerDragEnd: ((String?, RNLatLng) -> Unit)? = null
407418
var onIndoorBuildingFocused: ((RNIndoorBuilding) -> Unit)? = null
408419
var onIndoorLevelActivated: ((RNIndoorLevel) -> Unit)? = null
420+
var onInfoWindowPress: ((String?) -> Unit)? = null
421+
var onInfoWindowClose: ((String?) -> Unit)? = null
422+
var onInfoWindowLongPress: ((String?) -> Unit)? = null
423+
var onMyLocationPress: ((RNLocation) -> Unit)? = null
424+
var onMyLocationButtonPress: ((Boolean) -> Unit)? = null
409425
var onCameraChangeStart: ((RNRegion, RNCamera, Boolean) -> Unit)? = null
410426
var onCameraChange: ((RNRegion, RNCamera, Boolean) -> Unit)? = null
411427
var onCameraChangeComplete: ((RNRegion, RNCamera, Boolean) -> Unit)? = null
@@ -936,6 +952,11 @@ class GoogleMapsViewImpl(
936952
setOnMapLongClickListener(null)
937953
setOnPoiClickListener(null)
938954
setOnMarkerDragListener(null)
955+
setOnInfoWindowClickListener(null)
956+
setOnInfoWindowCloseListener(null)
957+
setOnInfoWindowLongClickListener(null)
958+
setOnMyLocationClickListener(null)
959+
setOnMyLocationButtonClickListener(null)
939960
}
940961
googleMap = null
941962
mapView?.apply {
@@ -993,7 +1014,7 @@ class GoogleMapsViewImpl(
9931014
override fun onMarkerClick(marker: Marker): Boolean {
9941015
marker.showInfoWindow()
9951016
onMarkerPress?.invoke(marker.tag?.toString())
996-
return true
1017+
return false
9971018
}
9981019

9991020
override fun onPolylineClick(polyline: Polyline) {
@@ -1059,6 +1080,27 @@ class GoogleMapsViewImpl(
10591080
override fun onPoiClick(poi: PointOfInterest) {
10601081
onPoiPress?.invoke(poi.placeId, poi.name, poi.latLng.toRnLatLng())
10611082
}
1083+
1084+
override fun onInfoWindowClick(marker: Marker) {
1085+
onInfoWindowPress?.invoke(marker.tag?.toString())
1086+
}
1087+
1088+
override fun onInfoWindowClose(marker: Marker) {
1089+
onInfoWindowClose?.invoke(marker.tag?.toString())
1090+
}
1091+
1092+
override fun onInfoWindowLongClick(marker: Marker) {
1093+
onInfoWindowLongPress?.invoke(marker.tag?.toString())
1094+
}
1095+
1096+
override fun onMyLocationClick(location: Location) {
1097+
onMyLocationPress?.invoke(location.toRnLocation())
1098+
}
1099+
1100+
override fun onMyLocationButtonClick(): Boolean {
1101+
onMyLocationButtonPress?.invoke(true)
1102+
return false
1103+
}
10621104
}
10631105

10641106
private inline fun onUi(crossinline block: () -> Unit) {

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,31 @@ class RNGoogleMapsPlusView(
371371
view.onIndoorLevelActivated = cb
372372
}
373373

374+
override var onInfoWindowPress: ((String?) -> Unit)? = null
375+
set(cb) {
376+
view.onInfoWindowPress = cb
377+
}
378+
379+
override var onInfoWindowClose: ((String?) -> Unit)? = null
380+
set(cb) {
381+
view.onInfoWindowClose = cb
382+
}
383+
384+
override var onInfoWindowLongPress: ((String?) -> Unit)? = null
385+
set(cb) {
386+
view.onInfoWindowLongPress = cb
387+
}
388+
389+
override var onMyLocationPress: ((RNLocation) -> Unit)? = null
390+
set(cb) {
391+
view.onMyLocationPress = cb
392+
}
393+
394+
override var onMyLocationButtonPress: ((Boolean) -> Unit)? = null
395+
set(cb) {
396+
view.onMyLocationButtonPress = cb
397+
}
398+
374399
override var onCameraChangeStart: ((RNRegion, RNCamera, Boolean) -> Unit)? = null
375400
set(cb) {
376401
view.onCameraChangeStart = cb

example/src/components/MapWrapper.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ export default function MapWrapper(props: Props) {
9696
}}
9797
initialProps={props.initialProps ?? initialProps}
9898
uiSettings={props.uiSettings ?? uiSettings}
99+
myLocationEnabled={props.myLocationEnabled ?? true}
100+
trafficEnabled={props.trafficEnabled ?? false}
101+
indoorEnabled={props.indoorEnabled ?? false}
99102
style={[styles.map, props.style]}
100103
userInterfaceStyle={
101104
props.userInterfaceStyle ?? (theme.dark ? 'dark' : 'light')
@@ -190,6 +193,33 @@ export default function MapWrapper(props: Props) {
190193
console.log('Indoor level activated', level),
191194
}
192195
)}
196+
onInfoWindowPress={callback(
197+
props.onInfoWindowPress ?? {
198+
f: (id?: string) => console.log('InfoWindow press:', id),
199+
}
200+
)}
201+
onInfoWindowClose={callback(
202+
props.onInfoWindowClose ?? {
203+
f: (id?: string) => console.log('InfoWindow close:', id),
204+
}
205+
)}
206+
onInfoWindowLongPress={callback(
207+
props.onInfoWindowLongPress ?? {
208+
f: (id?: string) => console.log('InfoWindow long press:', id),
209+
}
210+
)}
211+
onMyLocationPress={callback(
212+
props.onMyLocationPress ?? {
213+
f: (location: RNLocation) =>
214+
console.log('MyLocation press:', location),
215+
}
216+
)}
217+
onMyLocationButtonPress={callback(
218+
props.onMyLocationButtonPress ?? {
219+
f: (pressed: boolean) =>
220+
console.log('MyLocation button press', pressed),
221+
}
222+
)}
193223
onCameraChangeStart={callback(
194224
props.onCameraChangeStart ?? {
195225
f: (r: RNRegion, cam: RNCamera, g: boolean) =>

ios/GoogleMapViewImpl.swift

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@ GMSIndoorDisplayDelegate {
277277
var onMarkerDragEnd: ((String?, RNLatLng) -> Void)?
278278
var onIndoorBuildingFocused: ((RNIndoorBuilding) -> Void)?
279279
var onIndoorLevelActivated: ((RNIndoorLevel) -> Void)?
280+
var onInfoWindowPress: ((String?) -> Void)?
281+
var onInfoWindowClose: ((String?) -> Void)?
282+
var onInfoWindowLongPress: ((String?) -> Void)?
283+
var onMyLocationPress: ((RNLocation) -> Void)?
284+
var onMyLocationButtonPress: ((Bool) -> Void)?
280285
var onCameraChangeStart: ((RNRegion, RNCamera, Bool) -> Void)?
281286
var onCameraChange: ((RNRegion, RNCamera, Bool) -> Void)?
282287
var onCameraChangeComplete: ((RNRegion, RNCamera, Bool) -> Void)?
@@ -782,7 +787,7 @@ GMSIndoorDisplayDelegate {
782787
mapView.selectedMarker = marker
783788
self.onMarkerPress?(marker.userData as? String, )
784789
}
785-
return true
790+
return false
786791
}
787792

788793
func mapView(_ mapView: GMSMapView, didTap overlay: GMSOverlay) {
@@ -855,4 +860,43 @@ GMSIndoorDisplayDelegate {
855860
)
856861
}
857862
}
863+
864+
func mapView(_ mapView: GMSMapView, didTapInfoWindowOf marker: GMSMarker) {
865+
onMain {
866+
self.onInfoWindowPress?(marker.userData as? String)
867+
}
868+
}
869+
870+
func mapView(_ mapView: GMSMapView, didCloseInfoWindowOf marker: GMSMarker) {
871+
onMain {
872+
self.onInfoWindowClose?(marker.userData as? String)
873+
}
874+
}
875+
876+
func mapView(
877+
_ mapView: GMSMapView,
878+
didLongPressInfoWindowOf marker: GMSMarker
879+
) {
880+
onMain {
881+
self.onInfoWindowLongPress?(marker.userData as? String)
882+
}
883+
}
884+
885+
func mapView(
886+
_ mapView: GMSMapView,
887+
didTapMyLocation location: CLLocationCoordinate2D
888+
) {
889+
onMain {
890+
self.mapView?.myLocation.map {
891+
self.onMyLocationPress?($0.toRnLocation())
892+
}
893+
}
894+
}
895+
896+
func didTapMyLocationButton(for mapView: GMSMapView) -> Bool {
897+
onMain {
898+
self.onMyLocationButtonPress?(true)
899+
}
900+
return false
901+
}
858902
}

ios/RNGoogleMapsPlusView.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,26 @@ final class RNGoogleMapsPlusView: HybridRNGoogleMapsPlusViewSpec {
385385
didSet { impl.onIndoorLevelActivated = onIndoorLevelActivated }
386386
}
387387
@MainActor
388+
var onInfoWindowPress: ((String?) -> Void)?{
389+
didSet { impl.onInfoWindowPress = onInfoWindowPress }
390+
}
391+
@MainActor
392+
var onInfoWindowClose: ((String?) -> Void)?{
393+
didSet { impl.onInfoWindowClose = onInfoWindowClose }
394+
}
395+
@MainActor
396+
var onInfoWindowLongPress: ((String?) -> Void)?{
397+
didSet { impl.onInfoWindowLongPress = onInfoWindowLongPress }
398+
}
399+
@MainActor
400+
var onMyLocationPress: ((RNLocation) -> Void)?{
401+
didSet { impl.onMyLocationPress = onMyLocationPress }
402+
}
403+
@MainActor
404+
var onMyLocationButtonPress: ((Bool) -> Void)? {
405+
didSet { impl.onMyLocationButtonPress = onMyLocationButtonPress }
406+
}
407+
@MainActor
388408
var onCameraChangeStart: ((RNRegion, RNCamera, Bool) -> Void)? {
389409
didSet { impl.onCameraChangeStart = onCameraChangeStart }
390410
}

src/RNGoogleMapsPlusView.nitro.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ export interface RNGoogleMapsPlusViewProps extends HybridViewProps {
6868
onMarkerDragEnd?: (id: string | undefined, location: RNLatLng) => void;
6969
onIndoorBuildingFocused?: (indoorBuilding: RNIndoorBuilding) => void;
7070
onIndoorLevelActivated?: (indoorLevel: RNIndoorLevel) => void;
71+
onInfoWindowPress?: (id?: string) => void;
72+
onInfoWindowClose?: (id?: string) => void;
73+
onInfoWindowLongPress?: (id?: string) => void;
74+
onMyLocationPress?: (location: RNLocation) => void;
75+
onMyLocationButtonPress?: (pressed: boolean) => void;
7176
onCameraChangeStart?: (
7277
region: RNRegion,
7378
camera: RNCamera,

0 commit comments

Comments
 (0)