Allow library items to be dragged into other apps

This commit is contained in:
Jackson Harper
2023-05-24 16:44:43 +08:00
parent 8ba320e3d5
commit 4cf5eef261
3 changed files with 20 additions and 2 deletions

View File

@ -66,6 +66,13 @@ public extension LinkedItem {
var unwrappedSavedAt: Date { savedAt ?? Date() }
var unwrappedCreatedAt: Date { createdAt ?? Date() }
var deepLink: URL? {
if let id = id {
return URL(string: "omnivore://read/\(id)")
}
return nil
}
var hasLabels: Bool {
(labels?.count ?? 0) > 0
}

View File

@ -40,8 +40,7 @@ public extension DeepLink {
case "saved-search":
let named = url.path.replacingOccurrences(of: "/", with: "")
return .savedSearch(named: named)
case "read":
case "shareExtensionRequestID":
case "read", "shareExtensionRequestID":
let requestID = url.path.replacingOccurrences(of: "/", with: "")
return .webAppLinkRequest(requestID: requestID)
default:

View File

@ -2,6 +2,17 @@ import Models
import SwiftUI
import Utils
public extension View {
func draggableItem(item: LinkedItem) -> some View {
if #available(iOS 16.0, *), let url = item.deepLink {
return AnyView(self.draggable(url) {
Label(item.unwrappedTitle, systemImage: "link")
})
}
return AnyView(self)
}
}
public struct LibraryItemCard: View {
let viewer: Viewer?
let tapHandler: () -> Void
@ -27,6 +38,7 @@ public struct LibraryItemCard: View {
}
}
.padding(.bottom, 8)
.draggableItem(item: item)
}
var isFullyRead: Bool {