From 95c6306295055b1bdebb0cb656aec1ad55a1ab6e Mon Sep 17 00:00:00 2001 From: Darron Schall Date: Tue, 5 Nov 2024 12:18:34 -0500 Subject: [PATCH] fix: Prevent Clustering with composable content from displaying default markers (#615) Wait until we have both a non-null clusterManager and renderer created before configuring the cluster manager listeners. This is a small optimization that prevents setting the listeners on the default renderer when the clusterManger is first created (before the renderer is created). Wait until the renderer is created before configuring the map for clustering. This prevents the default renderer from rendering markers. --- .../android/compose/clustering/Clustering.kt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/maps-compose-utils/src/main/java/com/google/maps/android/compose/clustering/Clustering.kt b/maps-compose-utils/src/main/java/com/google/maps/android/compose/clustering/Clustering.kt index dba8bcaa..4f3ae4fb 100644 --- a/maps-compose-utils/src/main/java/com/google/maps/android/compose/clustering/Clustering.kt +++ b/maps-compose-utils/src/main/java/com/google/maps/android/compose/clustering/Clustering.kt @@ -62,7 +62,8 @@ import kotlinx.coroutines.launch clusterManager.setOnClusterItemInfoWindowClickListener(onClusterItemInfoWindowClick) clusterManager.setOnClusterItemInfoWindowLongClickListener(onClusterItemInfoWindowLongClick) } - if (clusterManager != null) { + // Wait for renderer to apply before clustering + if (clusterManager != null && clusterManager.renderer == clusterRenderer) { Clustering( items = items, clusterManager = clusterManager, @@ -128,21 +129,22 @@ public fun Clustering( ) { val clusterManager = rememberClusterManager() val renderer = rememberClusterRenderer(clusterContent, clusterItemContent, clusterManager) - SideEffect { - if (clusterManager?.renderer != renderer) { - clusterManager?.renderer = renderer ?: return@SideEffect - } - } SideEffect { clusterManager ?: return@SideEffect + renderer ?: return@SideEffect + + if (clusterManager.renderer != renderer) { + clusterManager.renderer = renderer + } + clusterManager.setOnClusterClickListener(onClusterClick) clusterManager.setOnClusterItemClickListener(onClusterItemClick) clusterManager.setOnClusterItemInfoWindowClickListener(onClusterItemInfoWindowClick) clusterManager.setOnClusterItemInfoWindowLongClickListener(onClusterItemInfoWindowLongClick) } - if (clusterManager != null) { + if (clusterManager != null && renderer != null) { Clustering( items = items, clusterManager = clusterManager,