Skip to content

Instantly share code, notes, and snippets.

@navsing
Created August 27, 2020 21:57
Show Gist options
  • Save navsing/03a3fac6d3e43e288467f10950b635b5 to your computer and use it in GitHub Desktop.
Save navsing/03a3fac6d3e43e288467f10950b635b5 to your computer and use it in GitHub Desktop.
Recreate iOS share sheet to any app in a minute
import SwiftUI
struct ShareSheet: View {
@State var show = false
@State var items: [Any] = []
var body: some View {
VStack {
Button(action: {
//Add Logic to add items here
self.show.toggle()
}) {
Text("Share").padding().foregroundColor(.white)
}.background(Color.black).cornerRadius(10)
}.sheet(isPresented: $show) {
ShareSheetView(items: items).edgesIgnoringSafeArea(.all)
}
}
}
struct ShareSheetView: UIViewControllerRepresentable {
let items: [Any]
func makeUIViewController(context: Context) -> some UIActivityViewController {
return UIActivityViewController(activityItems: items, applicationActivities: nil)
}
func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment