googlemaps / android-maps-compose

Jetpack Compose composables for the Maps SDK for Android
https://developers.google.com/maps/documentation/android-sdk/maps-compose
Apache License 2.0
1.16k stars 143 forks source link

Does GoogleMap call onClick on MarkerComposable during composition? #611

Open alghe-global opened 3 months ago

alghe-global commented 3 months ago

Hi,

I'm using com.google.maps.android:maps-compose:5.0.3 with build.gradle.kts in Kotlin 2.0 and latest compiler and Compose.

I'm developing an app where I attached a marker to each object I'm giving as input to a Composable which calls GoogleMap composable.

I'm composing MarkerComposable in two ways:

  1. All objects as input that the user hasn't selected
  2. The object as input the user has selected

To complicate a bit things, I am keeping state regarding which object is the currently selected one in ViewModel.

When a user clicks on the marker in the Map in UI on the device (Android phone, for example), the currently selected object is updated to that marker.

I was updating state even if the Marker was currently the selected one. Removing this code and leaving code to update the currently selected object only in MarkerComposable that are not matching the currently selected seems to have solved the issue where duplicate MarkerComposable were created.

As this is a strange fix for me and one that doesn't really make sense, I've to ask: does GoogleMap call onClick on MarkerComposable during composition?