@maplibre/maplibre-react-native 11.0.0-beta.7 → 11.0.0-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -50,7 +50,8 @@ class MLRNMarkerView(
50
50
  override fun onChildViewRemoved(
51
51
  parent: View?,
52
52
  child: View?,
53
- ) {}
53
+ ) {
54
+ }
54
55
  },
55
56
  )
56
57
  for (i in 0 until view.childCount) {
@@ -1,16 +1,12 @@
1
1
  package org.maplibre.reactnative.components.annotations.markerview
2
2
 
3
3
  import android.content.Context
4
- import android.view.MotionEvent
5
4
  import android.view.ViewGroup
6
5
  import com.facebook.react.views.view.ReactViewGroup
7
6
 
8
7
  /**
9
- * Custom ReactViewGroup that allows content to render outside its bounds (#642).
10
- * This is used as a wrapper for Marker content to prevent clipping.
11
- *
12
8
  * Based on rnmapbox/maps implementation:
13
- * https://github.com/rnmapbox/maps/blob/main/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerViewContent.kt
9
+ * https://github.com/rnmapbox/maps/blob/512c50865f322fa89e0d20066b4a0fb10f080cb5/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerViewContent.kt
14
10
  */
15
11
  class MLRNMarkerViewContent(
16
12
  context: Context,
@@ -32,19 +28,18 @@ class MLRNMarkerViewContent(
32
28
  }
33
29
 
34
30
  /**
35
- * Request that the parent (MapView) not intercept touch events when touching marker content.
36
- * This allows TouchableOpacity, Pressable, etc. to receive touch events properly (#557, #1018).
31
+ * Returns the authoritative content size from the first child view.
32
+ * The child is laid out by React Native before this wrapper is added to the map,
33
+ * so its dimensions are reliable even before this view's own layout pass runs.
37
34
  */
38
- override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
39
- // Request that parent (MapView) doesn't intercept this touch sequence
40
- parent?.requestDisallowInterceptTouchEvent(true)
41
- return super.onInterceptTouchEvent(event)
35
+ fun getContentSize(): Pair<Float, Float> {
36
+ val child = getChildAt(0) ?: return Pair(width.toFloat(), height.toFloat())
37
+ val w = if (child.width > 0) child.width else width
38
+ val h = if (child.height > 0) child.height else height
39
+ return Pair(w.toFloat(), h.toFloat())
42
40
  }
43
41
  }
44
42
 
45
- /**
46
- * Extension function to disable all forms of clipping on a ViewGroup
47
- */
48
43
  private fun ViewGroup.allowRenderingOutside() {
49
44
  clipChildren = false
50
45
  clipToPadding = false
@@ -1,9 +1,8 @@
1
1
  package org.maplibre.reactnative.components.annotations.markerview
2
2
 
3
3
  import android.graphics.PointF
4
+ import android.graphics.RectF
4
5
  import android.view.View
5
- import android.view.ViewGroup
6
- import android.widget.FrameLayout
7
6
  import org.maplibre.android.geometry.LatLng
8
7
  import org.maplibre.android.maps.MapLibreMap
9
8
  import org.maplibre.android.maps.MapView
@@ -13,7 +12,7 @@ class MarkerViewManager(
13
12
  private val map: MapLibreMap,
14
13
  ) {
15
14
  data class MarkerInfo(
16
- val view: View,
15
+ val view: MLRNMarkerViewContent,
17
16
  var latLng: LatLng,
18
17
  var anchorX: Float = 0f,
19
18
  var anchorY: Float = 0f,
@@ -25,7 +24,7 @@ class MarkerViewManager(
25
24
  private var isDestroyed = false
26
25
 
27
26
  fun addMarker(
28
- view: View,
27
+ view: MLRNMarkerViewContent,
29
28
  latLng: LatLng,
30
29
  anchorX: Float = 0f,
31
30
  anchorY: Float = 0f,
@@ -35,12 +34,6 @@ class MarkerViewManager(
35
34
  val markerInfo = MarkerInfo(view, latLng, anchorX, anchorY, offsetX, offsetY)
36
35
  markers.add(markerInfo)
37
36
 
38
- if (view is ViewGroup) {
39
- view.clipChildren = false
40
- view.clipToPadding = false
41
- view.clipToOutline = false
42
- }
43
-
44
37
  if (view.parent == null) {
45
38
  mapView.clipChildren = false
46
39
  mapView.clipToPadding = false
@@ -73,8 +66,7 @@ class MarkerViewManager(
73
66
  private fun updateMarkerPosition(marker: MarkerInfo) {
74
67
  val view = marker.view
75
68
  val screenPos: PointF = map.projection.toScreenLocation(marker.latLng)
76
- val viewWidth = if (view.width > 0) view.width.toFloat() else view.measuredWidth.toFloat()
77
- val viewHeight = if (view.height > 0) view.height.toFloat() else view.measuredHeight.toFloat()
69
+ val (viewWidth, viewHeight) = view.getContentSize()
78
70
  val anchorOffsetX = viewWidth * marker.anchorX
79
71
  val anchorOffsetY = viewHeight * marker.anchorY
80
72
  view.x = screenPos.x - anchorOffsetX + marker.offsetX
@@ -83,6 +75,18 @@ class MarkerViewManager(
83
75
 
84
76
  fun findMarkerByView(view: View): MarkerInfo? = markers.find { it.view == view }
85
77
 
78
+ fun isPointInsideMarker(screenPoint: PointF): Boolean {
79
+ for (marker in markers) {
80
+ val v = marker.view
81
+ if (v.visibility != View.VISIBLE) continue
82
+ val (w, h) = v.getContentSize()
83
+ val rect = RectF(v.x, v.y, v.x + w, v.y + h)
84
+ if (rect.contains(screenPoint.x, screenPoint.y)) return true
85
+ }
86
+
87
+ return false
88
+ }
89
+
86
90
  fun updateMarkerCoordinate(
87
91
  markerInfo: MarkerInfo,
88
92
  latLng: LatLng,
@@ -561,6 +561,10 @@ open class MLRNMapView(
561
561
 
562
562
  val screenPoint = mapLibreMap!!.projection.toScreenLocation(latLng)
563
563
 
564
+ if (markerViewManager?.isPointInsideMarker(screenPoint) == true) {
565
+ return true
566
+ }
567
+
564
568
  val hits: MutableMap<String, MutableList<Feature>?> = HashMap()
565
569
  val hitPressableSources: MutableList<MLRNPressableSource<*>> = ArrayList()
566
570
  for (pressableSource in this.pressableSources) {
@@ -608,6 +612,11 @@ open class MLRNMapView(
608
612
  }
609
613
 
610
614
  val screenPoint = mapLibreMap!!.projection.toScreenLocation(latLng)
615
+
616
+ if (markerViewManager?.isPointInsideMarker(screenPoint) == true) {
617
+ return true
618
+ }
619
+
611
620
  screenPoint.x /= this.displayDensity
612
621
  screenPoint.y /= this.displayDensity
613
622
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@maplibre/maplibre-react-native",
3
3
  "description": "React Native library for creating maps with MapLibre Native for Android & iOS",
4
- "version": "11.0.0-beta.7",
4
+ "version": "11.0.0-beta.8",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "provenance": true