@craft-native/ios 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.
package/package.json
CHANGED
package/templates/CraftApp.swift
CHANGED
|
@@ -5748,9 +5748,11 @@ struct CraftWebView: UIViewRepresentable {
|
|
|
5748
5748
|
return
|
|
5749
5749
|
}
|
|
5750
5750
|
var items: [Any] = []
|
|
5751
|
-
|
|
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) {
|
|
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
|
-
|
|
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) {
|
|
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:
|
|
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
|
}
|