aboutsummaryrefslogtreecommitdiff
path: root/foray/Coordinators
diff options
context:
space:
mode:
authorNicholas Tay <nick@windblume.net>2022-07-18 00:07:21 +1000
committerNicholas Tay <nick@windblume.net>2022-07-18 00:07:21 +1000
commit8b255702c674bf1bfeca96697711f6e4f088dfdb (patch)
tree98a3ee132dd02973ca1e5c02136b3fe539b22275 /foray/Coordinators
parentbd7761216a065b0dd859cb19d709996739a240cd (diff)
downloadforayios-8b255702c674bf1bfeca96697711f6e4f088dfdb.tar.gz
forayios-8b255702c674bf1bfeca96697711f6e4f088dfdb.tar.bz2
forayios-8b255702c674bf1bfeca96697711f6e4f088dfdb.zip
Try out 'share' aka UIActivityViewController
Diffstat (limited to '')
-rw-r--r--foray/Coordinators/ForayCoordinator.swift32
1 files changed, 32 insertions, 0 deletions
diff --git a/foray/Coordinators/ForayCoordinator.swift b/foray/Coordinators/ForayCoordinator.swift
index 874f486..972bfb8 100644
--- a/foray/Coordinators/ForayCoordinator.swift
+++ b/foray/Coordinators/ForayCoordinator.swift
@@ -7,6 +7,7 @@
import Foundation
import UIKit
+import LinkPresentation
class ForayCoordinator: Coordinator {
var childCoordinators = [Coordinator]()
@@ -36,4 +37,35 @@ class ForayCoordinator: Coordinator {
func hideLoading() {
loadingOverlay.hide()
}
+
+ func share(item: PenguinItemViewModel) {
+ let itemSource = ForayLinkPresentationSource(title: "\(item.name) (#\(item.id))", shareURL: URL(string: "https://nick.tay.blue/")!)
+ let activity = UIActivityViewController(activityItems: [itemSource], applicationActivities: nil)
+ navigationController.present(activity, animated: true)
+ }
+}
+
+class ForayLinkPresentationSource: NSObject, UIActivityItemSource {
+ private let metadata: LPLinkMetadata
+
+ func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) -> LPLinkMetadata? {
+ return metadata
+ }
+
+ func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any {
+ guard let url = metadata.originalURL else { return "" }
+ return url.absoluteURL
+ }
+
+ func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? {
+ return metadata.originalURL
+ }
+
+ init(title: String, shareURL: URL) {
+ metadata = LPLinkMetadata()
+ metadata.iconProvider = NSItemProvider(contentsOf: Bundle.main.url(forResource: "spy", withExtension: "png"))
+ metadata.originalURL = shareURL
+ metadata.url = shareURL
+ metadata.title = title
+ }
}