When I use a code like this to present a ShareSheet
import SwiftUI
extension UIApplication {
static let keyWindow = keyWindowScene?.windows.filter(\.isKeyWindow).first
static let keyWindowScene = shared.connectedScenes.first { $0.activationState == .foregroundActive } as? UIWindowScene
}
extension View {
func shareSheet(isPresented: Binding<Bool>, items: [Any]) -> some View {
guard isPresented.wrappedValue else { return self }
let activityViewController = UIActivityViewController(activityItems: items, applicationActivities: nil)
let presentedViewController = UIApplication.keyWindow?.rootViewController?.presentedViewController ?? UIApplication.keyWindow?.rootViewController
activityViewController.completionWithItemsHandler = { _, _, _, _ in isPresented.wrappedValue = false }
presentedViewController?.present(activityViewController, animated: true)
return self
}
}
struct ContentView: View {
@State private var isPresentingShareSheet = false
var body: some View {
Button("Present Share Sheet") { isPresentingShareSheet = true }
.shareSheet(isPresented: $isPresentingShareSheet, items: ["Share me!"])
}
}
A button named COPY is always present on the sharesheet itself.
When I press copy, what exactly is being copied and from where?
If this copy means the text or element that is selected when the sharesheet is triggered this creates me a problem, because I want to pass a rich text that is composed of a title, an image and a long description.
Can I define a function to run when that button is pressed?