craft-native 0.0.191 → 0.0.193

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.
@@ -286,7 +286,10 @@ internal class CraftNativeServices(
286
286
  else -> Intent(Intent.ACTION_SEND).apply { type = "text/plain" }
287
287
  }
288
288
  if (text.isNotBlank()) intent.putExtra(Intent.EXTRA_TEXT, text)
289
- options.optString("title").takeIf { it.isNotBlank() }?.let { intent.putExtra(Intent.EXTRA_SUBJECT, it) }
289
+ options.optString("title").takeIf { it.isNotBlank() }?.let {
290
+ intent.putExtra(Intent.EXTRA_SUBJECT, it)
291
+ intent.putExtra(Intent.EXTRA_TITLE, it)
292
+ }
290
293
  intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
291
294
  host.startActivity(Intent.createChooser(intent, options.optString("title").ifBlank { null }))
292
295
  // Android does not say whether something was shared; the sheet opened.
@@ -2458,6 +2458,8 @@ private data class LayoutBounds(
2458
2458
  */
2459
2459
  private class CraftNativeActivityIndicator(context: Context) :
2460
2460
  android.widget.ProgressBar(context, null, android.R.attr.progressBarStyleHorizontal) {
2461
+ var indicatorScale = 1f
2462
+
2461
2463
  init {
2462
2464
  val spinner = android.widget.ProgressBar(context).indeterminateDrawable
2463
2465
  indeterminateDrawable = spinner
@@ -4903,8 +4905,7 @@ class MainActivity : AppCompatActivity() {
4903
4905
  is Number -> (requestedSize.toDouble() / 24.0).takeIf { it.isFinite() }?.toFloat()?.coerceAtLeast(0.5f) ?: 1f
4904
4906
  else -> 1f
4905
4907
  }
4906
- scaleX = scale
4907
- scaleY = scale
4908
+ indicatorScale = scale
4908
4909
  val animating = props.optBoolean("animating", true)
4909
4910
  isIndeterminate = animating
4910
4911
  visibility = if (!animating && props.optBoolean("hidesWhenStopped", true)) View.GONE else View.VISIBLE
@@ -5111,7 +5112,7 @@ class MainActivity : AppCompatActivity() {
5111
5112
  val pressOutHandler = craftNativeEventName(events, "onPressOut").takeIf { it.isNotBlank() }
5112
5113
  if (pressInHandler != null) screen.pressInHandlers[control] = pressInHandler else screen.pressInHandlers.remove(control)
5113
5114
  if (pressOutHandler != null) screen.pressOutHandlers[control] = pressOutHandler else screen.pressOutHandlers.remove(control)
5114
- if (type != "Button" && type != "Link" && type != "TextInput" && type != "Picker" && type != "DatePicker" && type != "Modal" && type != "Switch" && type != "Slider" && type != "ActivityIndicator" && type != "KeyboardAvoidingView" && type != "StatusBar" && type != "RefreshControl" && type != "Map") {
5115
+ if (type != "Button" && type != "Link" && type != "Checkbox" && type != "TextInput" && type != "Picker" && type != "DatePicker" && type != "Modal" && type != "Switch" && type != "Slider" && type != "ActivityIndicator" && type != "KeyboardAvoidingView" && type != "StatusBar" && type != "RefreshControl" && type != "Map") {
5115
5116
  val handler = craftNativeEventName(events, "onPress", "onClick")
5116
5117
  val disabled = props.optBoolean("disabled", false)
5117
5118
  val target = listOf(props.opt("href"), props.opt("to"))
@@ -5546,8 +5547,11 @@ class MainActivity : AppCompatActivity() {
5546
5547
  private fun applyTransform(view: View, transforms: JSONArray?) {
5547
5548
  view.translationX = 0f
5548
5549
  view.translationY = 0f
5549
- view.scaleX = 1f
5550
- view.scaleY = 1f
5550
+ // Reconciliation reapplies transforms; start from the control's
5551
+ // intrinsic scale rather than erasing its authored indicator size.
5552
+ val intrinsicScale = (view as? CraftNativeActivityIndicator)?.indicatorScale ?: 1f
5553
+ view.scaleX = intrinsicScale
5554
+ view.scaleY = intrinsicScale
5551
5555
  view.rotation = 0f
5552
5556
  view.rotationX = 0f
5553
5557
  view.rotationY = 0f
package/dist/cli.js CHANGED
@@ -3424,7 +3424,7 @@ function pinCraftNativeDependency(packagePath, craftVersion) {
3424
3424
  `);
3425
3425
  }
3426
3426
  // package.json
3427
- var version = "0.0.191";
3427
+ var version = "0.0.193";
3428
3428
 
3429
3429
  // bin/cli.ts
3430
3430
  var spawnedFrom = process6.env[CRAFT_CLI_SPAWN_MARKER];
package/dist/index.cjs CHANGED
@@ -309,7 +309,7 @@ function craftBinaryNotFoundMessage(triedPath) {
309
309
  `);
310
310
  }
311
311
  // package.json
312
- var version = "0.0.191";
312
+ var version = "0.0.193";
313
313
 
314
314
  // src/sdk-version.ts
315
315
  var SDK_VERSION = version;
package/dist/index.js CHANGED
@@ -57,7 +57,7 @@ function craftBinaryNotFoundMessage(triedPath) {
57
57
  `);
58
58
  }
59
59
  // package.json
60
- var version = "0.0.191";
60
+ var version = "0.0.193";
61
61
 
62
62
  // src/sdk-version.ts
63
63
  var SDK_VERSION = version;
@@ -5748,9 +5748,11 @@ struct CraftWebView: UIViewRepresentable {
5748
5748
  return
5749
5749
  }
5750
5750
  var items: [Any] = []
5751
- if let title = options["title"] as? String, !title.isEmpty { items.append(title) }
5751
+ let title = options["title"] as? String ?? ""
5752
5752
  if let text = options["text"] as? String, !text.isEmpty { items.append(text) }
5753
- if let urlString = options["url"] as? String, let url = URL(string: urlString) { items.append(url) }
5753
+ if let urlString = options["url"] as? String, let url = URL(string: urlString) {
5754
+ items.append(CraftShareLink(url: url, title: title))
5755
+ } else if !title.isEmpty { items.append(title) }
5754
5756
  if let files = options["files"] as? [String] {
5755
5757
  for file in files {
5756
5758
  if let url = URL(string: file), url.isFileURL { items.append(url) }
@@ -726,6 +726,11 @@ private func craftNativeAlignContentCode(_ value: String) -> UInt32 {
726
726
  }
727
727
  }
728
728
 
729
+ /// Keep the indicator's intrinsic size separate from authored style transforms.
730
+ private final class CraftNativeActivityIndicatorView: UIActivityIndicatorView {
731
+ var indicatorScale: CGFloat = 1
732
+ }
733
+
729
734
  /// A native screen's `<Video>`: AVPlayerViewController in place.
730
735
  ///
731
736
  /// With sound, a video takes the audio session as a playing sound does
@@ -5510,7 +5515,7 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
5510
5515
  updateHandler(nonEmptyHandler(events["onValueChange"]) ?? nonEmptyHandler(events["onChange"]), for: slider)
5511
5516
  updateAuxiliaryHandler(events["onSlidingComplete"], in: &sliderCompleteHandlers, for: slider)
5512
5517
  case "ActivityIndicator":
5513
- let indicator = result as! UIActivityIndicatorView
5518
+ let indicator = result as! CraftNativeActivityIndicatorView
5514
5519
  let requestedSize = props["size"]
5515
5520
  indicator.style = (requestedSize as? String) == "large" ? .large : .medium
5516
5521
  let scale: CGFloat
@@ -5522,7 +5527,7 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
5522
5527
  } else {
5523
5528
  scale = 1
5524
5529
  }
5525
- indicator.transform = CGAffineTransform(scaleX: scale, y: scale)
5530
+ indicator.indicatorScale = scale
5526
5531
  indicator.color = color(props["color"]) ?? .tintColor
5527
5532
  indicator.hidesWhenStopped = props["hidesWhenStopped"] as? Bool ?? true
5528
5533
  if props["animating"] as? Bool == false {
@@ -5728,7 +5733,7 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
5728
5733
  slider.addTarget(self, action: #selector(sliderFinished(_:)), for: [.touchUpInside, .touchUpOutside, .touchCancel])
5729
5734
  return slider
5730
5735
  case "ActivityIndicator":
5731
- return UIActivityIndicatorView(style: .medium)
5736
+ return CraftNativeActivityIndicatorView(style: .medium)
5732
5737
  case "StatusBar", "RefreshControl":
5733
5738
  return CraftNativeFlowView()
5734
5739
  case "Image":
@@ -6437,8 +6442,9 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
6437
6442
  }
6438
6443
 
6439
6444
  private func applyTransform(_ raw: Any?, to view: UIView) {
6440
- view.transform = .identity
6445
+ let intrinsicScale = (view as? CraftNativeActivityIndicatorView)?.indicatorScale ?? 1
6441
6446
  view.layer.transform = CATransform3DIdentity
6447
+ view.transform = CGAffineTransform(scaleX: intrinsicScale, y: intrinsicScale)
6442
6448
  guard let transforms = raw as? [[String: Any]] else { return }
6443
6449
  var affine = CGAffineTransform.identity
6444
6450
  var threeDimensional = CATransform3DIdentity
@@ -6461,6 +6467,7 @@ final class CraftNativeScreenController: UIViewController, UIScrollViewDelegate,
6461
6467
  hasThreeDimensionalRotation = true
6462
6468
  }
6463
6469
  }
6470
+ affine = affine.scaledBy(x: intrinsicScale, y: intrinsicScale)
6464
6471
  if hasThreeDimensionalRotation {
6465
6472
  view.layer.transform = CATransform3DConcat(CATransform3DMakeAffineTransform(affine), threeDimensional)
6466
6473
  } else {
@@ -1,5 +1,6 @@
1
1
  import AVFoundation
2
2
  import Foundation
3
+ import LinkPresentation
3
4
  import UIKit
4
5
  import UserNotifications
5
6
 
@@ -687,6 +688,32 @@ enum CraftNativePush {
687
688
 
688
689
  // MARK: - Share sheet
689
690
 
691
+ /// A URL stays a URL in Messages, AirDrop and Copy. Its title belongs in the
692
+ /// system preview and mail subject, rather than becoming a second text item.
693
+ final class CraftShareLink: NSObject, UIActivityItemSource {
694
+ let url: URL
695
+ let title: String
696
+
697
+ init(url: URL, title: String) {
698
+ self.url = url
699
+ self.title = title
700
+ }
701
+
702
+ func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any { url }
703
+
704
+ func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? { url }
705
+
706
+ func activityViewController(_ activityViewController: UIActivityViewController, subjectForActivityType activityType: UIActivity.ActivityType?) -> String { title }
707
+
708
+ func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) -> LPLinkMetadata? {
709
+ let metadata = LPLinkMetadata()
710
+ metadata.originalURL = url
711
+ metadata.url = url
712
+ if !title.isEmpty { metadata.title = title }
713
+ return metadata
714
+ }
715
+ }
716
+
690
717
  /// `craft.share` on a native screen: the system share sheet with the page's
691
718
  /// options (`title`, `text`, `url`, `files`), plus `image`, a picture by URL
692
719
  /// that is shared as the picture rather than as its address. Answers true
@@ -694,9 +721,11 @@ enum CraftNativePush {
694
721
  enum CraftNativeShare {
695
722
  static func share(_ options: [String: Any], done: @escaping (Result<Any, CraftNativeActionError>) -> Void) {
696
723
  var items: [Any] = []
697
- if let title = options["title"] as? String, !title.isEmpty { items.append(title) }
724
+ let title = options["title"] as? String ?? ""
698
725
  if let text = options["text"] as? String, !text.isEmpty { items.append(text) }
699
- if let address = options["url"] as? String, let url = URL(string: address) { items.append(url) }
726
+ if let address = options["url"] as? String, let url = URL(string: address) {
727
+ items.append(CraftShareLink(url: url, title: title))
728
+ } else if !title.isEmpty { items.append(title) }
700
729
  // A path or file URL, or a file craft.files made (`{ path, name }`).
701
730
  let files = (options["files"] as? [Any] ?? []).compactMap { item -> String? in
702
731
  item as? String ?? (item as? [String: Any])?["path"] as? String
@@ -715,7 +744,7 @@ enum CraftNativeShare {
715
744
  if let error { done(.failure(CraftNativeActionError(code: "SHARE_ERROR", message: error.localizedDescription))) }
716
745
  else { done(.success(completed)) }
717
746
  }
718
- if !CraftPresenter.present(sheet, from: nil, anchor: nil) {
747
+ if !CraftPresenter.present(sheet, from: nil, anchor: CraftPresenter.rect(options["anchor"])) {
719
748
  done(.failure(CraftNativeActionError(code: "SHARE_ERROR", message: "Unable to present the share sheet")))
720
749
  }
721
750
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "craft-native",
3
- "version": "0.0.191",
3
+ "version": "0.0.193",
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>",