From 7bd0a1c4c056264781efef8fc9ea61970fd351e0 Mon Sep 17 00:00:00 2001 From: James Rich <2199651+jamesarich@users.noreply.github.com> Date: Tue, 9 Dec 2025 11:09:25 -0600 Subject: [PATCH] fix(maps): Enable lite mode and fix recomposition for inline maps (#3936) Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com> --- .../feature/node/component/InlineMap.kt | 70 +++++++++++-------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/feature/node/src/google/kotlin/org/meshtastic/feature/node/component/InlineMap.kt b/feature/node/src/google/kotlin/org/meshtastic/feature/node/component/InlineMap.kt index b4a56914d..167d35612 100644 --- a/feature/node/src/google/kotlin/org/meshtastic/feature/node/component/InlineMap.kt +++ b/feature/node/src/google/kotlin/org/meshtastic/feature/node/component/InlineMap.kt @@ -19,9 +19,10 @@ package org.meshtastic.feature.node.component import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue +import androidx.compose.runtime.key import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color +import com.google.android.gms.maps.GoogleMapOptions import com.google.android.gms.maps.model.CameraPosition import com.google.android.gms.maps.model.LatLng import com.google.maps.android.compose.Circle @@ -36,6 +37,8 @@ import org.meshtastic.core.database.model.Node import org.meshtastic.core.ui.component.NodeChip import org.meshtastic.core.ui.component.precisionBitsToMeters +private const val DEFAULT_ZOOM = 15f + @OptIn(MapsComposeExperimentalApi::class) @Composable internal fun InlineMap(node: Node, modifier: Modifier = Modifier) { @@ -45,36 +48,41 @@ internal fun InlineMap(node: Node, modifier: Modifier = Modifier) { true -> ComposeMapColorScheme.DARK else -> ComposeMapColorScheme.LIGHT } - - val location = LatLng(node.latitude, node.longitude) - val cameraState = rememberCameraPositionState { position = CameraPosition.fromLatLngZoom(location, 15f) } - GoogleMap( - mapColorScheme = mapColorScheme, - modifier = modifier, - uiSettings = - MapUiSettings( - zoomControlsEnabled = true, - mapToolbarEnabled = false, - compassEnabled = false, - myLocationButtonEnabled = false, - rotationGesturesEnabled = false, - scrollGesturesEnabled = false, - tiltGesturesEnabled = false, - zoomGesturesEnabled = false, - ), - cameraPositionState = cameraState, - ) { - val precisionMeters = precisionBitsToMeters(node.position.precisionBits) - val latLng = LatLng(node.latitude, node.longitude) - if (precisionMeters > 0) { - Circle( - center = latLng, - radius = precisionMeters, - fillColor = Color(node.colors.second).copy(alpha = 0.2f), - strokeColor = Color(node.colors.second), - strokeWidth = 2f, - ) + key(node.num) { + val location = LatLng(node.latitude, node.longitude) + val cameraState = rememberCameraPositionState { + position = CameraPosition.fromLatLngZoom(location, DEFAULT_ZOOM) + } + + GoogleMap( + mapColorScheme = mapColorScheme, + modifier = modifier, + uiSettings = + MapUiSettings( + zoomControlsEnabled = true, + mapToolbarEnabled = false, + compassEnabled = false, + myLocationButtonEnabled = false, + rotationGesturesEnabled = false, + scrollGesturesEnabled = false, + tiltGesturesEnabled = false, + zoomGesturesEnabled = false, + ), + googleMapOptionsFactory = { GoogleMapOptions().liteMode(true) }, + cameraPositionState = cameraState, + ) { + val precisionMeters = precisionBitsToMeters(node.position.precisionBits) + val latLng = LatLng(node.latitude, node.longitude) + if (precisionMeters > 0) { + Circle( + center = latLng, + radius = precisionMeters, + fillColor = Color(node.colors.second).copy(alpha = 0.2f), + strokeColor = Color(node.colors.second), + strokeWidth = 2f, + ) + } + MarkerComposable(state = rememberUpdatedMarkerState(position = latLng)) { NodeChip(node = node) } } - MarkerComposable(state = rememberUpdatedMarkerState(position = latLng)) { NodeChip(node = node) } } }