Skip to content

Commit

Permalink
fix: onMarkerClick and onMarkerInfoWindowTapped on Android (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
jokerttu authored Nov 1, 2024
1 parent 8c7f569 commit 1c461be
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void onRecenterButtonClick() {

@Override
public void onMarkerClick(Marker marker) {
emitEvent("onMapReady", ObjectTranslationUtil.getMapFromMarker(marker));
emitEvent("onMarkerClick", ObjectTranslationUtil.getMapFromMarker(marker));
}

@Override
Expand All @@ -138,7 +138,7 @@ public void onGroundOverlayClick(GroundOverlay groundOverlay) {

@Override
public void onMarkerInfoWindowTapped(Marker marker) {
emitEvent("onInfoWindowClick", ObjectTranslationUtil.getMapFromMarker(marker));
emitEvent("onMarkerInfoWindowTapped", ObjectTranslationUtil.getMapFromMarker(marker));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void onRecenterButtonClick() {

@Override
public void onMarkerClick(Marker marker) {
emitEvent("onMapReady", ObjectTranslationUtil.getMapFromMarker(marker));
emitEvent("onMarkerClick", ObjectTranslationUtil.getMapFromMarker(marker));
}

@Override
Expand All @@ -150,7 +150,7 @@ public void onGroundOverlayClick(GroundOverlay groundOverlay) {

@Override
public void onMarkerInfoWindowTapped(Marker marker) {
emitEvent("onInfoWindowClick", ObjectTranslationUtil.getMapFromMarker(marker));
emitEvent("onMarkerInfoWindowTapped", ObjectTranslationUtil.getMapFromMarker(marker));
}

@Override
Expand Down
10 changes: 8 additions & 2 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import * as React from 'react';
import {
NavigationContainer,
useIsFocused,
useNavigation,
type NavigationProp,
} from '@react-navigation/native';
Expand All @@ -37,15 +38,20 @@ export type StackNavigation = NavigationProp<RootStackParamList>;

const HomeScreen = () => {
const { navigate } = useNavigation<StackNavigation>();
const isFocused = useIsFocused();

return (
<View style={styles.container}>
<View style={styles.buttonContainer}>
<Button title="Navigation" onPress={() => navigate('Navigation')} />
<Button
title="Navigation"
onPress={() => isFocused && navigate('Navigation')}
/>
</View>
<View style={styles.buttonContainer}>
<Button
title="Multiple Maps"
onPress={() => navigate('Multiple maps')}
onPress={() => isFocused && navigate('Multiple maps')}
/>
</View>
</View>
Expand Down
6 changes: 4 additions & 2 deletions example/src/screens/NavigationScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ const NavigationScreen = () => {
useEffect(() => {
(async () => {
const isAvailable = await mapViewAutoController.isAutoScreenAvailable();
console.log('isAutoScreenAvailable:', isAvailable);
setMapViewAutoAvailable(isAvailable);
})();
}, [mapViewAutoController]);
Expand Down Expand Up @@ -312,7 +311,10 @@ const NavigationScreen = () => {
onMapReady,
onMarkerClick: (marker: Marker) => {
console.log('onMarkerClick:', marker);
mapViewController?.removeMarker(marker.id);
showSnackbar('Removing marker in 5 seconds');
setTimeout(() => {
mapViewController?.removeMarker(marker.id);
}, 5000);
},
onPolygonClick: (polygon: Polygon) => {
console.log('onPolygonClick:', polygon);
Expand Down

0 comments on commit 1c461be

Please sign in to comment.