I'm trying to come out of a Preferences sheet and then immediately show a Share sheet (since it appears to be impossible to show a Share sheet from within another sheet.) I'm trying to call the Share sheet from the onDismiss handler of the Preferences sheet, like so:
Button("Prefs") {
theCurrentLog.prefsAreVisible.toggle()
}
.sheet(isPresented:$theCurrentLog.prefsAreVisible, onDismiss: {
guard let data = currentPrefs.exportURL else { return }
let av = UIActivityViewController(activityItems: [data], applicationActivities: nil)
UIApplication.shared.windows.first?.rootViewController?.present(av, animated: true, completion: nil)
}) {
Prefs(currentPrefs: $currentPrefs)
}
However, this causes a crash with the following error: 'UIPopoverPresentationController (<UIPopoverPresentationController: 0x15edddf10>) should have a non-nil sourceView or barButtonItem set before the presentation occurs.'
I have no idea how to specify a non-nil sourceView.