Skip to content

Commit

Permalink
fix(android): Ignore the onMeasure on MarkerView while adding it to t…
Browse files Browse the repository at this point in the history
…he annotationManager (#3242)
  • Loading branch information
mfazekas authored Dec 5, 2023
1 parent f6ee1b0 commit 30f65d9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
)
}
}

Expand Down

0 comments on commit 30f65d9

Please sign in to comment.