@craft-native/android 0.0.174 → 0.0.175

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@craft-native/android",
3
- "version": "0.0.174",
3
+ "version": "0.0.175",
4
4
  "homepage": "https://github.com/craft-native/craft/tree/main/packages/android#readme",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,9 +1,11 @@
1
1
  package {{PACKAGE_NAME}}
2
2
 
3
3
  import android.animation.ValueAnimator
4
+ import android.Manifest
4
5
  import android.content.ClipData
5
6
  import android.content.ClipboardManager
6
7
  import android.content.Context
8
+ import android.content.pm.PackageManager
7
9
  import android.content.res.ColorStateList
8
10
  import android.content.res.Configuration
9
11
  import android.database.ContentObserver
@@ -517,9 +519,11 @@ private class CraftNativeMapView(context: Context) : FrameLayout(context), OnMap
517
519
  "terrain" -> GoogleMap.MAP_TYPE_TERRAIN
518
520
  else -> GoogleMap.MAP_TYPE_NORMAL
519
521
  }
522
+ val showUserLocation = pendingProps.optBoolean("showsUserLocation", false) && hasLocationPermission()
523
+ runCatching { map.isMyLocationEnabled = showUserLocation }
520
524
  val nextMarkers = mutableMapOf<String, Pair<LatLng, String?>>()
521
525
  val nextHandlers = mutableMapOf<String, String>()
522
- val nextPolylines = mutableMapOf<String, Pair<List<LatLng>, Int>>()
526
+ val nextPolylines = mutableMapOf<String, Triple<List<LatLng>, Int, Float>>()
523
527
  for (index in 0 until pendingChildren.length()) {
524
528
  val child = pendingChildren.optJSONObject(index) ?: continue
525
529
  val type = child.optString("type").lowercase()
@@ -536,7 +540,10 @@ private class CraftNativeMapView(context: Context) : FrameLayout(context), OnMap
536
540
  .takeIf { it.isNotBlank() }?.let { nextHandlers[id] = it }
537
541
  }
538
542
  } else if (type == "mappolyline" || type == "polyline") {
539
- if (points.size > 1) nextPolylines[id] = points to color(props.optString("strokeColor"))
543
+ if (points.size > 1) {
544
+ val width = props.optDouble("strokeWidth", 3.0).toFloat().takeIf { it.isFinite() && it > 0 } ?: 3f
545
+ nextPolylines[id] = Triple(points, color(props.optString("strokeColor")), width)
546
+ }
540
547
  }
541
548
  }
542
549
  markers.keys.filter { nextMarkers[it] == null }.forEach { markers.remove(it)?.remove() }
@@ -554,7 +561,7 @@ private class CraftNativeMapView(context: Context) : FrameLayout(context), OnMap
554
561
  polylines.values.forEach { it.remove() }
555
562
  polylines.clear()
556
563
  for ((id, value) in nextPolylines) {
557
- polylines[id] = map.addPolyline(PolylineOptions().addAll(value.first).color(value.second).width(3f))
564
+ polylines[id] = map.addPolyline(PolylineOptions().addAll(value.first).color(value.second).width(value.third))
558
565
  }
559
566
  if (pendingProps.optBoolean("fitToBounds", false)) fitToBounds()
560
567
  region(pendingProps.optJSONObject("region") ?: pendingProps.optJSONObject("initialRegion"))?.let { bounds ->
@@ -578,14 +585,20 @@ private class CraftNativeMapView(context: Context) : FrameLayout(context), OnMap
578
585
 
579
586
  override fun onAttachedToWindow() {
580
587
  super.onAttachedToWindow()
588
+ mapView.onStart()
581
589
  mapView.onResume()
582
590
  }
583
591
 
584
592
  override fun onDetachedFromWindow() {
585
593
  mapView.onPause()
594
+ mapView.onStop()
586
595
  super.onDetachedFromWindow()
587
596
  }
588
597
 
598
+ private fun hasLocationPermission(): Boolean =
599
+ ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED ||
600
+ ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED
601
+
589
602
  private fun coordinates(geometry: JSONArray?): List<LatLng> {
590
603
  if (geometry == null) return emptyList()
591
604
  return (0 until geometry.length() - 1 step 2).mapNotNull { index ->