From cd2c7289b74d43811b12ca08f6e09a77235cebbe Mon Sep 17 00:00:00 2001 From: Fynn Godau Date: Tue, 1 Oct 2024 19:27:54 +0200 Subject: [PATCH] Fix InfoWindow when provided view already has parent Since views cannot have two parents at the same time, we encounter a crash when a client provides us with a view to be used as an InfoWindow which already has a parent. The simple solution is to remove the parent. --- .../org/microg/gms/maps/mapbox/model/InfoWindow.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/play-services-maps/core/mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/model/InfoWindow.kt b/play-services-maps/core/mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/model/InfoWindow.kt index 16f0471d8b..b9514a17d8 100644 --- a/play-services-maps/core/mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/model/InfoWindow.kt +++ b/play-services-maps/core/mapbox/src/main/kotlin/org/microg/gms/maps/mapbox/model/InfoWindow.kt @@ -39,7 +39,12 @@ import kotlin.math.* */ fun IInfoWindowAdapter.getInfoWindowViewFor(marker: IMarkerDelegate, mapContext: MapContext): View? { - getInfoWindow(marker).unwrap()?.let { return it } + getInfoWindow(marker).unwrap()?.let { view -> + return view.apply { + // Remove any previous parents mistakenly added by the client + parent?.let { (it as ViewManager).removeView(this) } + } + } getInfoContents(marker).unwrap()?.let { view -> // Detach from previous BubbleLayout parent, if exists @@ -95,7 +100,7 @@ class InfoWindow internal constructor( /** * Close this [InfoWindow] if it is visible, otherwise calling this will do nothing. * - * @param silent `OnInfoWindowCloseListener` is only called if `silent` is not `false` + * @param silent `OnInfoWindowCloseListener` is only called if `silent` is `false` */ fun close(silent: Boolean = false) { if (isVisible) {