Don’t present share service picker twice

This commit is contained in:
Angelo Stavrow 2020-12-11 15:07:27 -05:00
parent b8bbfbb208
commit c99df92c6b
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
2 changed files with 11 additions and 16 deletions

View File

@ -10,15 +10,14 @@ struct ActivePostToolbarView: View {
PostEditorStatusToolbarView(post: activePost)
HStack(spacing: 4) {
Button(
action: { self.isPresentingSharingServicePicker = true },
action: {
self.isPresentingSharingServicePicker = true
},
label: { Image(systemName: "square.and.arrow.up") }
)
.disabled(activePost.status == PostStatus.local.rawValue)
.popover(isPresented: $isPresentingSharingServicePicker) {
PostEditorSharingPicker(
isPresented: $isPresentingSharingServicePicker,
sharingItems: createPostUrl()
)
PostEditorSharingPicker(sharingItems: createPostUrl())
}
Button(action: { publishPost(activePost) }, label: { Image(systemName: "paperplane") })
.disabled(activePost.body.isEmpty || activePost.status == PostStatus.published.rawValue)

View File

@ -1,23 +1,20 @@
import SwiftUI
struct PostEditorSharingPicker: NSViewRepresentable {
@Binding var isPresented: Bool
var sharingItems: [Any] = []
func makeNSView(context: Context) -> some NSView {
let view = NSView()
return view
}
func updateNSView(_ nsView: NSViewType, context: Context) {
if isPresented {
let picker = NSSharingServicePicker(items: sharingItems)
picker.delegate = context.coordinator
DispatchQueue.main.async {
picker.show(relativeTo: .zero, of: nsView, preferredEdge: .minY)
picker.show(relativeTo: .zero, of: view, preferredEdge: .minY)
}
return view
}
func updateNSView(_ nsView: NSViewType, context: Context) {
}
func makeCoordinator() -> Coordinator {
@ -34,8 +31,7 @@ struct PostEditorSharingPicker: NSViewRepresentable {
_ sharingServicePicker: NSSharingServicePicker,
didChoose service: NSSharingService?
) {
sharingServicePicker.delegate = nil // Cleanup
self.owner.isPresented = false // Dismiss
sharingServicePicker.delegate = nil
}
}
}