Skip to content
Open
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
20 changes: 20 additions & 0 deletions android/src/main/java/com/luggmaps/LuggMarkerView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.luggmaps
import android.content.Context
import android.graphics.Canvas
import android.view.View
import android.view.ViewGroup
import androidx.core.graphics.createBitmap
import androidx.core.view.isNotEmpty
import com.facebook.react.views.view.ReactViewGroup
Expand All @@ -23,6 +24,10 @@ interface LuggMarkerViewDelegate {
class LuggMarkerView(context: Context) : ReactViewGroup(context) {
private var scaleUpdateRunnable: Runnable? = null

companion object {
private const val OFFSCREEN_TRANSLATION_X = -10000f
}

var name: String? = null
private set

Expand Down Expand Up @@ -170,10 +175,25 @@ class LuggMarkerView(context: Context) : ReactViewGroup(context) {
visibility = GONE
}

private fun ensureContentViewAttached() {
if (contentView.parent == null) {
// Add contentView to the hierarchy so Fabric triggers measure/layout,
// but push it offscreen so it is never visually rendered on the map.
// createContentBitmap() calls contentView.draw(canvas) which draws
// relative to the view's own coordinate space, unaffected by translation.
contentView.translationX = OFFSCREEN_TRANSLATION_X
super.addView(contentView, 0, ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
))
}
}

override fun addView(child: View, index: Int) {
if (child is LuggCalloutView) {
calloutView = child
} else {
ensureContentViewAttached()
contentView.addView(child, index)
}
didLayout = false
Expand Down
Loading