mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Don’t present share service picker twice
This commit is contained in:
parent
b8bbfbb208
commit
c99df92c6b
@ -10,15 +10,14 @@ struct ActivePostToolbarView: View {
|
|||||||
PostEditorStatusToolbarView(post: activePost)
|
PostEditorStatusToolbarView(post: activePost)
|
||||||
HStack(spacing: 4) {
|
HStack(spacing: 4) {
|
||||||
Button(
|
Button(
|
||||||
action: { self.isPresentingSharingServicePicker = true },
|
action: {
|
||||||
|
self.isPresentingSharingServicePicker = true
|
||||||
|
},
|
||||||
label: { Image(systemName: "square.and.arrow.up") }
|
label: { Image(systemName: "square.and.arrow.up") }
|
||||||
)
|
)
|
||||||
.disabled(activePost.status == PostStatus.local.rawValue)
|
.disabled(activePost.status == PostStatus.local.rawValue)
|
||||||
.popover(isPresented: $isPresentingSharingServicePicker) {
|
.popover(isPresented: $isPresentingSharingServicePicker) {
|
||||||
PostEditorSharingPicker(
|
PostEditorSharingPicker(sharingItems: createPostUrl())
|
||||||
isPresented: $isPresentingSharingServicePicker,
|
|
||||||
sharingItems: createPostUrl()
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
Button(action: { publishPost(activePost) }, label: { Image(systemName: "paperplane") })
|
Button(action: { publishPost(activePost) }, label: { Image(systemName: "paperplane") })
|
||||||
.disabled(activePost.body.isEmpty || activePost.status == PostStatus.published.rawValue)
|
.disabled(activePost.body.isEmpty || activePost.status == PostStatus.published.rawValue)
|
||||||
|
@ -1,23 +1,20 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct PostEditorSharingPicker: NSViewRepresentable {
|
struct PostEditorSharingPicker: NSViewRepresentable {
|
||||||
@Binding var isPresented: Bool
|
|
||||||
var sharingItems: [Any] = []
|
var sharingItems: [Any] = []
|
||||||
|
|
||||||
func makeNSView(context: Context) -> some NSView {
|
func makeNSView(context: Context) -> some NSView {
|
||||||
let view = 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
|
return view
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateNSView(_ nsView: NSViewType, context: Context) {
|
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 {
|
func makeCoordinator() -> Coordinator {
|
||||||
@ -34,8 +31,7 @@ struct PostEditorSharingPicker: NSViewRepresentable {
|
|||||||
_ sharingServicePicker: NSSharingServicePicker,
|
_ sharingServicePicker: NSSharingServicePicker,
|
||||||
didChoose service: NSSharingService?
|
didChoose service: NSSharingService?
|
||||||
) {
|
) {
|
||||||
sharingServicePicker.delegate = nil // Cleanup
|
sharingServicePicker.delegate = nil
|
||||||
self.owner.isPresented = false // Dismiss
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user