I finally ended up finding a solution on my own. You need to set isSheetPresented back to false once you're done with it, else, it doesn't work, maybe because isPresented looks for change since the last call.
Once you change it back to false through the completionHandler, the problem is fixed.
import SwiftUI
struct ContentView: View {
@State private var isSheetPresented:Bool = false
var body: some View {
Text("Hello, world!")
.padding()
Button(action: {
self.isSheetPresented = true
}) {
Text("Share")
}.sheet(isPresented: $isSheetPresented) {
ActivityView(isSheetPresented:$isSheetPresented,activityItems: ["this is some text that could normally be saved to files, but somehow, once you save it to files, or do something in other specific apps, the share button somehow doesn't work"], applicationActivities: [])
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct ActivityView: UIViewControllerRepresentable {
@Binding var isSheetPresented:Bool
var activityItems: [Any]
var
applicationActivities: [UIActivity]?
func makeUIViewController(context: UIViewControllerRepresentableContext<ActivityView>) -> UIActivityViewController {
let ac = UIActivityViewController(activityItems: activityItems,
applicationActivities: applicationActivities)
ac.completionWithItemsHandler = {(activityType: UIActivity.ActivityType?, completed:
Bool, arrayReturnedItems: [Any]?, error: Error?) in
isSheetPresented = false;}
return ac;
}
func updateUIViewController(_ uiViewController: UIActivityViewController,
context: UIViewControllerRepresentableContext<ActivityView>) {}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: