Skip to content

Commit

Permalink
ArchiveSharableToolbarContent now generic for ArchiveSharable (#963)
Browse files Browse the repository at this point in the history
  • Loading branch information
bolsinga authored Oct 11, 2024
1 parent b07e451 commit 33c52e9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
8 changes: 2 additions & 6 deletions Sources/Site/Music/UI/ArchiveSharableModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ struct ArchiveSharableModifier<T: ArchiveSharable>: ViewModifier {
let item: T?

func body(content: Content) -> some View {
if let item, let url = item.url {
content
.toolbar { ArchiveSharableToolbarContent(item: item, url: url) }
} else {
content
}
content
.toolbar { ArchiveSharableToolbarContent(item: item) }
}
}

Expand Down
26 changes: 13 additions & 13 deletions Sources/Site/Music/UI/ArchiveSharableToolbarContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@

import SwiftUI

struct ArchiveSharableToolbarContent: ToolbarContent {
struct ArchiveSharableToolbarContent<T: ArchiveSharable>: ToolbarContent {
let placement: ToolbarItemPlacement
let item: ArchiveSharable
let url: URL
let item: T?

internal init(placement: ToolbarItemPlacement = .primaryAction, item: ArchiveSharable, url: URL) {
internal init(placement: ToolbarItemPlacement = .primaryAction, item: T?) {
self.placement = placement
self.item = item
self.url = url
}

var body: some ToolbarContent {
ToolbarItem(placement: placement) {
#if !os(tvOS)
ShareLink(
item: url, subject: Text(item.subject), message: Text(item.message),
preview: SharePreview(Text(item.subject), image: Bundle.main.appIcon))
#else
EmptyView()
#endif
if let item, let url = item.url {
ToolbarItem(placement: placement) {
#if !os(tvOS)
ShareLink(
item: url, subject: Text(item.subject), message: Text(item.message),
preview: SharePreview(Text(item.subject), image: Bundle.main.appIcon))
#else
EmptyView()
#endif
}
}
}
}

0 comments on commit 33c52e9

Please sign in to comment.