Has anyone achieved MarkerInfoWindow recomposition...
# compose
p
Has anyone achieved MarkerInfoWindow recomposition in compose maps? I'm trying to update the
InfoWindowMarker
content of my google map in
Compose
, for that, I added a
onClick
to the InfoWindowMarker and when it's clicked, it changes a "favorite" variable which is hoisted. That favorite variable is passed to the
InfoWindowMarker
composable, and depending of that variable shows or not another Text. The problem is that when the marker is pressed, the variable is changed (I tested it under debug mode with a breakpoing) but the info window is not changed, the favorite Text doens't appear, it's like its not being recomposed.
This is my google map:
Copy code
GoogleMap(
    modifier = Modifier.fillMaxSize(),
    cameraPositionState = cameraPositionState
) {
    val bitmapDescriptor: BitmapDescriptor by remember { mutableStateOf(BitmapDescriptorFactory.fromResource(R.drawable.place)) }

    for (item in uiState.data) {
        var favorite by remember { mutableStateOf(false) }

        val markerState = rememberMarkerState(position = LatLng(item.lat, item.lon))
        CustomMarker(
            favorite = favorite,
            item = item,
            markerState = markerState,
            bitmapDescriptor = bitmapDescriptor,
            showMarker = showMarkers,
            onMarkerClicked = { favorite = !favorite }
        )
    }
}
This is my CustomMarker:
Copy code
@Composable
fun CustomMarker(
    favorite: Boolean,
    item: Item,
    markerState: MarkerState,
    bitmapDescriptor: BitmapDescriptor,
    showMarker: Boolean,
    onMarkerClicked: () -> Unit,
    modifier: Modifier = Modifier
) {
    MarkerInfoWindowContent(
        state = markerState,
        icon = bitmapDescriptor,
        visible = (showMarker),
        onInfoWindowClick = {
            onMarkerClicked()
        }
    ) {
        Column(
            modifier = modifier.wrapContentSize().padding(8.dp),
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            Text(text = item.id.toString(), color = Color.Red)
            Text(text = item.name, color = Color.Red)

            if (favorite)
                Text("favorite"}
        }
    }
}
c
Paulo changed his name? 😅 You should ask your google maps questions in an Android forum (maps compose is not multiplatform but Android only) . And I‘d file a bug on the maps issue tracker.
p
this issue seems to be related with compose/recompositions and the compose implementation of maps
c
Yes, and only Google can help you with that implementation.
That’s why you should file a bug in the maps issue tracker.
p
it is a good idea
with Android forum, you mean #C0B8M7BUY? or another slack dedicated to Android?
c
Neither. Google maps has it’s own issue tracker. Check the Google maps SDK website.
🤝 1