Skip to content

Commit

Permalink
Fix InfoWindow when provided view already has parent
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fynngodau authored and mar-v-in committed Nov 16, 2024
1 parent d18c6c1 commit cd2c728
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ import kotlin.math.*
*/

fun IInfoWindowAdapter.getInfoWindowViewFor(marker: IMarkerDelegate, mapContext: MapContext): View? {
getInfoWindow(marker).unwrap<View?>()?.let { return it }
getInfoWindow(marker).unwrap<View?>()?.let { view ->
return view.apply {
// Remove any previous parents mistakenly added by the client
parent?.let { (it as ViewManager).removeView(this) }
}
}

getInfoContents(marker).unwrap<View>()?.let { view ->
// Detach from previous BubbleLayout parent, if exists
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit cd2c728

Please sign in to comment.