diff --git a/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerView.kt b/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerView.kt index 8f2191815..59cbf0b06 100644 --- a/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerView.kt +++ b/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerView.kt @@ -122,13 +122,14 @@ class RNMBXMarkerView(context: Context?, private val mManager: RNMBXMarkerViewMa val options = getOptions() - + val content = view as? RNMBXMarkerViewContent; + content?.inAdd = true; + didAddToMap = true val annotation = mMapView?.viewAnnotationManager?.addViewAnnotation( view, options ) - didAddToMap = true - + content?.inAdd = false; } fun update() { diff --git a/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerViewContent.kt b/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerViewContent.kt index 94b157360..17b4e61ed 100644 --- a/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerViewContent.kt +++ b/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerViewContent.kt @@ -1,21 +1,29 @@ package com.rnmapbox.rnmbx.components.annotation import android.content.Context +import android.view.View.MeasureSpec import com.facebook.react.uimanager.MeasureSpecAssertions import com.facebook.react.views.view.ReactViewGroup class RNMBXMarkerViewContent(context: Context): ReactViewGroup(context) { + + var inAdd: Boolean = false // see https://github.com/rnmapbox/maps/pull/3235 override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { - try { + if (inAdd) { + val w = if (widthMeasureSpec == 0) { + MeasureSpec.makeMeasureSpec(measuredWidth, MeasureSpec.EXACTLY) + } else { + widthMeasureSpec + }; + val h = if (heightMeasureSpec == 0) { + MeasureSpec.makeMeasureSpec(measuredHeight, MeasureSpec.EXACTLY) + } else { + heightMeasureSpec + } + super.onMeasure(w, h) + } else { super.onMeasure(widthMeasureSpec, heightMeasureSpec) - } catch(e: IllegalStateException) { - val w = MeasureSpec.getSize(widthMeasureSpec) - val h = MeasureSpec.getSize(heightMeasureSpec) - setMeasuredDimension( - if (w == 0) measuredWidth else w, - if (h == 0) measuredHeight else h - ) } }