Skip to content

Commit 3c274a1

Browse files
committed
feat: add consumeOnMarkerPress and consumeOnMyLocationButtonPress to RNMapUiSettings
1 parent 7e0a4f1 commit 3c274a1

File tree

6 files changed

+25
-9
lines changed

6 files changed

+25
-9
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ class GoogleMapsViewImpl(
876876
marker.showInfoWindow()
877877
onMarkerPress?.invoke(marker.tag?.toString())
878878
}
879-
return false
879+
return uiSettings?.consumeOnMarkerPress ?: false
880880
}
881881

882882
override fun onPolylineClick(polyline: Polyline) =
@@ -963,6 +963,6 @@ class GoogleMapsViewImpl(
963963
onUi {
964964
onMyLocationButtonPress?.invoke(true)
965965
}
966-
return false
966+
return uiSettings?.consumeOnMyLocationButtonPress ?: false
967967
}
968968
}

example/src/components/MapWrapper.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ import type {
55
GoogleMapsViewRef,
66
RNCamera,
77
RNGoogleMapsPlusViewProps,
8+
RNInitialProps,
89
RNLatLng,
910
RNLocation,
11+
RNLocationConfig,
12+
RNMapPadding,
13+
RNMapUiSettings,
14+
RNMapZoomConfig,
1015
RNRegion,
1116
} from 'react-native-google-maps-plus';
1217
import {
@@ -47,7 +52,7 @@ export default function MapWrapper(props: Props) {
4752
const layout = useSafeAreaInsets();
4853

4954
const [mapLoaded, setMapLoaded] = React.useState(false);
50-
const initialProps = useMemo(
55+
const initialProps: RNInitialProps = useMemo(
5156
() => ({
5257
camera: {
5358
center: { latitude: 37.7749, longitude: -122.4194 },
@@ -57,7 +62,7 @@ export default function MapWrapper(props: Props) {
5762
[]
5863
);
5964

60-
const uiSettings = useMemo(
65+
const uiSettings: RNMapUiSettings = useMemo(
6166
() => ({
6267
allGesturesEnabled: true,
6368
compassEnabled: true,
@@ -70,19 +75,24 @@ export default function MapWrapper(props: Props) {
7075
tiltEnabled: true,
7176
zoomControlsEnabled: true,
7277
zoomGesturesEnabled: true,
78+
consumeOnMarkerPress: false,
79+
consumeOnMyLocationButtonPress: false,
7380
}),
7481
[]
7582
);
7683

77-
const mapPadding = useMemo(() => {
84+
const mapPadding: RNMapPadding = useMemo(() => {
7885
return props.children
7986
? { top: 20, left: 20, bottom: layout.bottom + 80, right: 20 }
8087
: { top: 20, left: 20, bottom: layout.bottom, right: 20 };
8188
}, [layout.bottom, props.children]);
8289

83-
const mapZoomConfig = useMemo(() => ({ min: 0, max: 20 }), []);
90+
const mapZoomConfig: RNMapZoomConfig = useMemo(
91+
() => ({ min: 0, max: 20 }),
92+
[]
93+
);
8494

85-
const locationConfig = useMemo(
95+
const locationConfig: RNLocationConfig = useMemo(
8696
() => ({
8797
android: {
8898
priority: RNAndroidLocationPriority.PRIORITY_HIGH_ACCURACY,

example/src/components/maptConfigDialog/validator.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ export const RNMapUiSettingsValidator = object({
128128
tiltEnabled: optional(boolean()),
129129
zoomControlsEnabled: optional(boolean()),
130130
zoomGesturesEnabled: optional(boolean()),
131+
consumeOnMarkerPress: optional(boolean()),
132+
consumeOnMyLocationButtonPress: optional(boolean()),
131133
});
132134

133135
export const RNMapZoomConfigValidator = object({

example/src/screens/BasicMapScreen.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export default function BasicMapScreen() {
3535
tiltEnabled: true,
3636
zoomControlsEnabled: true,
3737
zoomGesturesEnabled: true,
38+
consumeOnMarkerPress: false,
39+
consumeOnMyLocationButtonPress: false,
3840
},
3941
myLocationEnabled: true,
4042
buildingEnabled: undefined,

ios/GoogleMapViewImpl.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ GMSIndoorDisplayDelegate {
781781
mapView.selectedMarker = marker
782782
self.onMarkerPress?(marker.userData as? String, )
783783
}
784-
return false
784+
return uiSettings?.consumeOnMarkerPress ?? false
785785
}
786786

787787
func mapView(_ mapView: GMSMapView, didTap overlay: GMSOverlay) {
@@ -891,6 +891,6 @@ GMSIndoorDisplayDelegate {
891891
onMain {
892892
self.onMyLocationButtonPress?(true)
893893
}
894-
return false
894+
return uiSettings?.consumeOnMyLocationButtonPress ?? false
895895
}
896896
}

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export type RNMapUiSettings = {
2121
tiltEnabled?: boolean;
2222
zoomControlsEnabled?: boolean;
2323
zoomGesturesEnabled?: boolean;
24+
consumeOnMarkerPress?: boolean;
25+
consumeOnMyLocationButtonPress?: boolean;
2426
};
2527

2628
export type RNLatLng = {

0 commit comments

Comments
 (0)