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
3 changes: 2 additions & 1 deletion android/src/main/java/com/luggmaps/LuggPolylineView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.google.android.gms.maps.model.Polyline

interface LuggPolylineViewDelegate {
fun polylineViewDidUpdate(polylineView: LuggPolylineView)
fun polylineViewDidDrop(polylineView: LuggPolylineView)
}

data class AnimatedOptions(val duration: Long = 2150L, val easing: String = "linear", val trailLength: Float = 1f, val delay: Long = 0L)
Expand Down Expand Up @@ -67,8 +68,8 @@ class LuggPolylineView(context: Context) : ReactViewGroup(context) {
}

fun onDropViewInstance() {
delegate?.polylineViewDidDrop(this)
delegate = null
polyline?.remove()
polyline = null
}
}
14 changes: 12 additions & 2 deletions android/src/main/java/com/luggmaps/core/GoogleMapProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,10 @@ class GoogleMapProvider(private val context: Context) :
syncPolylineView(polylineView)
}

override fun polylineViewDidDrop(polylineView: LuggPolylineView) {
teardownPolyline(polylineView)
}

// endregion

// region PolygonViewDelegate
Expand Down Expand Up @@ -773,8 +777,12 @@ class GoogleMapProvider(private val context: Context) :
}

override fun removePolylineView(polylineView: LuggPolylineView) {
polylineAnimators[polylineView]?.destroy()
polylineAnimators.remove(polylineView)
teardownPolyline(polylineView)
}

private fun teardownPolyline(polylineView: LuggPolylineView) {
pendingPolylineViews.remove(polylineView)
polylineAnimators.remove(polylineView)?.destroy()
polylineView.polyline?.remove()
polylineView.polyline = null
}
Expand Down Expand Up @@ -812,6 +820,8 @@ class GoogleMapProvider(private val context: Context) :
private fun addPolylineViewToMap(polylineView: LuggPolylineView) {
val map = googleMap ?: return

polylineAnimators.remove(polylineView)?.destroy()

val options = PolylineOptions()
.width(polylineView.strokeWidth.dpToPx())
.zIndex(polylineView.zIndex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class PolylineAnimator {
// Clear spans before setting points to prevent IndexOutOfBoundsException
// when the new points list is shorter than what existing spans reference
poly.color = strokeColors.firstOrNull() ?: Color.BLACK
poly.points = ArrayList(reusablePoints)
poly.points = reusablePoints

if (strokeColors.size > 1) {
val segmentCount = reusablePoints.size - 1
Expand Down
Loading