Implement share popover for iPad

This commit is contained in:
Angelo Stavrow 2020-09-29 10:46:01 -04:00
parent eb83b0418c
commit 25c1009136
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
2 changed files with 20 additions and 9 deletions

View File

@ -7,12 +7,12 @@
<key>WriteFreely-MultiPlatform (iOS).xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>1</integer>
</dict>
<key>WriteFreely-MultiPlatform (macOS).xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<integer>0</integer>
</dict>
</dict>
</dict>

View File

@ -89,13 +89,6 @@ struct PostEditorView: View {
PostEditorStatusToolbarView(post: post)
}
ToolbarItemGroup(placement: .navigationBarTrailing) {
Button(action: {
sharePost()
}, label: {
Image(systemName: "square.and.arrow.up")
})
.disabled(post.postId == nil)
Button(action: {
publishPost()
}, label: {
@ -106,6 +99,12 @@ struct PostEditorView: View {
!model.account.isLoggedIn ||
!model.hasNetworkConnection
)
Button(action: {
sharePost()
}, label: {
Image(systemName: "square.and.arrow.up")
})
.disabled(post.postId == nil)
}
}
.onChange(of: post.hasNewerRemoteCopy, perform: { _ in
@ -158,8 +157,20 @@ struct PostEditorView: View {
"\(model.account.server)/\((model.selectedPost?.collectionAlias)!)/\((model.selectedPost?.slug)!)" :
"\(model.account.server)/\((model.selectedPost?.postId)!)" else { return }
guard let data = URL(string: urlString) else { return }
let activityView = UIActivityViewController(activityItems: [data], applicationActivities: nil)
UIApplication.shared.windows.first?.rootViewController?.present(activityView, animated: true, completion: nil)
if UIDevice.current.userInterfaceIdiom == .pad {
activityView.popoverPresentationController?.permittedArrowDirections = .up
activityView.popoverPresentationController?.sourceView = UIApplication.shared.windows.first
activityView.popoverPresentationController?.sourceRect = CGRect(
x: UIScreen.main.bounds.width,
y: -125,
width: 200,
height: 200
)
}
}
}