Share button

This commit is contained in:
Arkadiusz Fal
2021-10-27 00:59:59 +02:00
parent b50d915d8e
commit 544dc70c5d
11 changed files with 205 additions and 19 deletions

View File

@@ -4,6 +4,8 @@ import SwiftUI
struct ChannelPlaylistView: View {
var playlist: ChannelPlaylist
@State private var presentingShareSheet = false
@StateObject private var store = Store<ChannelPlaylist>()
@Environment(\.dismiss) private var dismiss
@@ -44,12 +46,26 @@ struct ChannelPlaylistView: View {
#endif
VerticalCells(items: items)
}
#if os(iOS)
.sheet(isPresented: $presentingShareSheet) {
ShareSheet(activityItems: [
accounts.api.shareURL(contentItem)
])
}
#endif
.onAppear {
resource?.addObserver(store)
resource?.loadIfNeeded()
}
#if !os(tvOS)
.toolbar {
ToolbarItem(placement: shareButtonPlacement) {
ShareButton(
contentItem: contentItem,
presentingShareSheet: $presentingShareSheet
)
}
ToolbarItem(placement: .cancellationAction) {
if inNavigationView {
Button("Done") {
@@ -64,6 +80,18 @@ struct ChannelPlaylistView: View {
.background(.thickMaterial)
#endif
}
private var shareButtonPlacement: ToolbarItemPlacement {
#if os(iOS)
.navigation
#else
.automatic
#endif
}
private var contentItem: ContentItem {
ContentItem(playlist: playlist)
}
}
struct ChannelPlaylistView_Previews: PreviewProvider {