craft-native 0.0.191 → 0.0.192

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.
@@ -5111,7 +5111,7 @@ class MainActivity : AppCompatActivity() {
5111
5111
  val pressOutHandler = craftNativeEventName(events, "onPressOut").takeIf { it.isNotBlank() }
5112
5112
  if (pressInHandler != null) screen.pressInHandlers[control] = pressInHandler else screen.pressInHandlers.remove(control)
5113
5113
  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") {
5114
+ 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
5115
  val handler = craftNativeEventName(events, "onPress", "onClick")
5116
5116
  val disabled = props.optBoolean("disabled", false)
5117
5117
  val target = listOf(props.opt("href"), props.opt("to"))
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.192";
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.192";
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.192";
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) }
@@ -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.192",
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>",