Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion android/src/main/java/com/luggmaps/LuggMapView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,14 @@ class LuggMapView(private val reactContext: ThemedReactContext) :

// region View Lifecycle

// Children whose removal from the map waits a loop, in case they come back
private val pendingRemovals = mutableSetOf<View>()

override fun addView(child: View?, index: Int) {
super.addView(child, index)
// Fabric moves a child (e.g. on a zIndex change) by removing and
// re-inserting it. Its map object is still there, so it's kept as is.
if (pendingRemovals.remove(child)) return
when (child) {
is LuggMapWrapperView -> mapWrapperView = child
is LuggMarkerView -> provider?.addMarkerView(child)
Expand All @@ -94,6 +100,15 @@ class LuggMapView(private val reactContext: ThemedReactContext) :

override fun removeViewAt(index: Int) {
val view = getChildAt(index)
super.removeViewAt(index)
if (view == null || view is LuggMapWrapperView) return
pendingRemovals.add(view)
post {
if (pendingRemovals.remove(view)) removeFromProvider(view)
}
}

private fun removeFromProvider(view: View) {
when (view) {
is LuggMarkerView -> provider?.removeMarkerView(view)
is LuggPolylineView -> provider?.removePolylineView(view)
Expand All @@ -102,7 +117,6 @@ class LuggMapView(private val reactContext: ThemedReactContext) :
is LuggGroundOverlayView -> provider?.removeGroundOverlayView(view)
is LuggTileOverlayView -> provider?.removeTileOverlayView(view)
}
super.removeViewAt(index)
}

override fun onAttachedToWindow() {
Expand Down
5 changes: 4 additions & 1 deletion android/src/main/java/com/luggmaps/core/GoogleMapProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,10 @@ class GoogleMapProvider(private val context: Context) :
}

if (markerView.marker == null) {
if (markerView.hasCustomView) return
// Custom views wait for their first layout. Fabric moves a laid-out
// marker (e.g. on a zIndex change) by removing and re-adding it, and no
// new layout follows, so it's added back here.
if (markerView.hasCustomView && !markerView.didLayout) return
addMarkerViewToMap(markerView)
return
}
Expand Down
Loading