From c99df92c6bc68d633ff4819ffe7d0ac44b88e494 Mon Sep 17 00:00:00 2001 From: Angelo Stavrow Date: Fri, 11 Dec 2020 15:07:27 -0500 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20present=20share=20service=20pic?= =?UTF-8?q?ker=20twice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- macOS/Navigation/ActivePostToolbarView.swift | 9 ++++----- macOS/PostEditor/PostEditorSharingPicker.swift | 18 +++++++----------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/macOS/Navigation/ActivePostToolbarView.swift b/macOS/Navigation/ActivePostToolbarView.swift index b7df978..991fb2c 100644 --- a/macOS/Navigation/ActivePostToolbarView.swift +++ b/macOS/Navigation/ActivePostToolbarView.swift @@ -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) diff --git a/macOS/PostEditor/PostEditorSharingPicker.swift b/macOS/PostEditor/PostEditorSharingPicker.swift index f754cd4..97d2c99 100644 --- a/macOS/PostEditor/PostEditorSharingPicker.swift +++ b/macOS/PostEditor/PostEditorSharingPicker.swift @@ -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() + let picker = NSSharingServicePicker(items: sharingItems) + picker.delegate = context.coordinator + + DispatchQueue.main.async { + picker.show(relativeTo: .zero, of: view, preferredEdge: .minY) + } 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) - } - } } 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 } } }