craft-native 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.
@@ -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 ->
package/dist/cli.js CHANGED
@@ -3303,7 +3303,7 @@ function pinCraftNativeDependency(packagePath, craftVersion) {
3303
3303
  `);
3304
3304
  }
3305
3305
  // package.json
3306
- var version = "0.0.174";
3306
+ var version = "0.0.175";
3307
3307
 
3308
3308
  // bin/cli.ts
3309
3309
  var spawnedFrom = process6.env[CRAFT_CLI_SPAWN_MARKER];
package/dist/index.cjs CHANGED
@@ -310,7 +310,7 @@ function craftBinaryNotFoundMessage(triedPath) {
310
310
  `);
311
311
  }
312
312
  // package.json
313
- var version = "0.0.174";
313
+ var version = "0.0.175";
314
314
 
315
315
  // src/sdk-version.ts
316
316
  var SDK_VERSION = version;
package/dist/index.js CHANGED
@@ -58,7 +58,7 @@ function craftBinaryNotFoundMessage(triedPath) {
58
58
  `);
59
59
  }
60
60
  // package.json
61
- var version = "0.0.174";
61
+ var version = "0.0.175";
62
62
 
63
63
  // src/sdk-version.ts
64
64
  var SDK_VERSION = version;
@@ -431,6 +431,7 @@ private final class CraftNativeMapView: MKMapView, MKMapViewDelegate {
431
431
  private var annotationsByID: [String: MKPointAnnotation] = [:]
432
432
  private var overlaysByID: [String: MKPolyline] = [:]
433
433
  private var overlayColors: [ObjectIdentifier: UIColor] = [:]
434
+ private var overlayWidths: [ObjectIdentifier: CGFloat] = [:]
434
435
  private(set) var markerHandlers: [String: String] = [:]
435
436
  var onMarkerTap: ((String) -> Void)?
436
437
 
@@ -453,6 +454,10 @@ private final class CraftNativeMapView: MKMapView, MKMapViewDelegate {
453
454
  isZoomEnabled = props["zoomEnabled"] as? Bool ?? true
454
455
  isRotateEnabled = props["rotateEnabled"] as? Bool ?? false
455
456
  mapType = Self.mapType(props["mapType"] as? String)
457
+ // Showing the user dot must not trigger a permission prompt from a
458
+ // renderer pass. The app's existing location capability owns that
459
+ // prompt; a map only opts in after authorization is already granted.
460
+ showsUserLocation = props["showsUserLocation"] as? Bool == true && Self.locationPermissionGranted()
456
461
 
457
462
  var nextMarkers: [String: (coordinate: CLLocationCoordinate2D, title: String?)] = [:]
458
463
  var nextHandlers: [String: String] = [:]
@@ -497,10 +502,12 @@ private final class CraftNativeMapView: MKMapView, MKMapViewDelegate {
497
502
  removeOverlays(Array(overlaysByID.values))
498
503
  overlaysByID.removeAll(keepingCapacity: true)
499
504
  overlayColors.removeAll(keepingCapacity: true)
505
+ overlayWidths.removeAll(keepingCapacity: true)
500
506
  for (id, value) in nextPolylines {
501
507
  let overlay = MKPolyline(coordinates: value.coordinates, count: value.coordinates.count)
502
508
  overlaysByID[id] = overlay
503
509
  overlayColors[ObjectIdentifier(overlay)] = value.color
510
+ overlayWidths[ObjectIdentifier(overlay)] = value.width
504
511
  addOverlay(overlay)
505
512
  }
506
513
 
@@ -542,7 +549,7 @@ private final class CraftNativeMapView: MKMapView, MKMapViewDelegate {
542
549
  func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
543
550
  let renderer = MKPolylineRenderer(overlay: overlay)
544
551
  renderer.strokeColor = overlayColors[ObjectIdentifier(overlay)] ?? .systemBlue
545
- renderer.lineWidth = 3
552
+ renderer.lineWidth = overlayWidths[ObjectIdentifier(overlay)] ?? 3
546
553
  return renderer
547
554
  }
548
555
 
@@ -585,6 +592,16 @@ private final class CraftNativeMapView: MKMapView, MKMapViewDelegate {
585
592
  default: return .standard
586
593
  }
587
594
  }
595
+
596
+ private static func locationPermissionGranted() -> Bool {
597
+ let status: CLAuthorizationStatus
598
+ if #available(iOS 14.0, *) {
599
+ status = CLLocationManager().authorizationStatus
600
+ } else {
601
+ status = CLLocationManager.authorizationStatus()
602
+ }
603
+ return status == .authorizedAlways || status == .authorizedWhenInUse
604
+ }
588
605
  }
589
606
 
590
607
  /// A WebView-free host for the first stx native vertical slice. The bundled
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "craft-native",
3
- "version": "0.0.174",
3
+ "version": "0.0.175",
4
4
  "type": "module",
5
5
  "description": "Build desktop apps with web languages - TypeScript SDK for Craft",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",