mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2025-03-14 09:45:42 +00:00
share sheet
This commit is contained in:
parent
69654e187e
commit
0064155825
2 changed files with 41 additions and 1 deletions
|
@ -20,3 +20,41 @@ func showShareSheet(items: [Any], completed: (() -> Void)? = nil) {
|
|||
presentedViewController.present(activityViewController, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
extension View {
|
||||
func shareSheet(item: Binding<ShareItem?>) -> some View {
|
||||
sheet(item: item) { item in
|
||||
Group {
|
||||
if #available(iOS 16.0, *) {
|
||||
ActivityView(item: item)
|
||||
.presentationDetents([.medium, .large])
|
||||
} else {
|
||||
ActivityView(item: item)
|
||||
}
|
||||
}.ignoresSafeArea()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ShareItem: Identifiable {
|
||||
let content: any Hashable
|
||||
var id: Int { content.hashValue }
|
||||
}
|
||||
|
||||
private struct ActivityView: UIViewControllerRepresentable {
|
||||
let item: ShareItem
|
||||
|
||||
func makeUIViewController(
|
||||
context: UIViewControllerRepresentableContext<ActivityView>
|
||||
) -> UIActivityViewController {
|
||||
UIActivityViewController(
|
||||
activityItems: [item.content],
|
||||
applicationActivities: nil
|
||||
)
|
||||
}
|
||||
|
||||
func updateUIViewController(
|
||||
_ uiViewController: UIActivityViewController,
|
||||
context: UIViewControllerRepresentableContext<ActivityView>
|
||||
) { }
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ struct UserAddressView: View {
|
|||
@State private var mailViewResult: Result<MFMailComposeResult, Error>? = nil
|
||||
@State private var alert: UserAddressAlert?
|
||||
@State private var progressIndicator = false
|
||||
@State private var shareItem: ShareItem?
|
||||
@FocusState private var keyboardVisible: Bool
|
||||
|
||||
private enum UserAddressAlert: Identifiable {
|
||||
|
@ -68,6 +69,7 @@ struct UserAddressView: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
.shareSheet(item: $shareItem)
|
||||
}
|
||||
|
||||
@Namespace private var bottomID
|
||||
|
@ -245,7 +247,7 @@ struct UserAddressView: View {
|
|||
|
||||
private func shareQRCodeButton(_ userAddress: UserContactLink) -> some View {
|
||||
Button {
|
||||
showShareSheet(items: [simplexChatLink(userAddress.connReqContact)])
|
||||
shareItem = ShareItem(content: simplexChatLink(userAddress.connReqContact))
|
||||
} label: {
|
||||
settingsRow("square.and.arrow.up", color: theme.colors.secondary) {
|
||||
Text("Share address")
|
||||
|
|
Loading…
Add table
Reference in a new issue