iOS: Add share sheet
This commit is contained in:
parent
fd2463b917
commit
6b98d55f59
|
@ -12,10 +12,12 @@ struct ContentView: View {
|
|||
@ObservedObject private var navigator: NavigationManager
|
||||
@State private var urlFieldContents: String
|
||||
@State private var showPreferencesSheet = false
|
||||
private let shareCurrentURL: () -> Void
|
||||
|
||||
init(navigator: NavigationManager) {
|
||||
init(navigator: NavigationManager, shareCurrentURL: @escaping () -> Void) {
|
||||
self.navigator = navigator
|
||||
self._urlFieldContents = State(initialValue: navigator.currentURL.absoluteString)
|
||||
self.shareCurrentURL = shareCurrentURL
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
|
@ -55,37 +57,47 @@ struct ContentView: View {
|
|||
|
||||
private var bottomBar: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
|
||||
Button(action: navigator.back, label: {
|
||||
Image(systemName: "arrow.left")
|
||||
.font(.system(size: 24))
|
||||
})
|
||||
.disabled(navigator.backStack.isEmpty)
|
||||
|
||||
Spacer()
|
||||
|
||||
Button(action: navigator.forward, label: {
|
||||
Image(systemName: "arrow.right")
|
||||
.font(.system(size: 24))
|
||||
})
|
||||
.disabled(navigator.forwardStack.isEmpty)
|
||||
|
||||
Spacer()
|
||||
|
||||
Button(action: navigator.reload, label: {
|
||||
Image(systemName: "arrow.clockwise")
|
||||
.font(.system(size: 24))
|
||||
})
|
||||
|
||||
Spacer()
|
||||
|
||||
Button(action: {
|
||||
showPreferencesSheet = true
|
||||
}, label: {
|
||||
Image(systemName: "gear")
|
||||
.font(.system(size: 24))
|
||||
})
|
||||
// use a group because this exceeds the 10 view limit :/
|
||||
Group {
|
||||
Spacer()
|
||||
|
||||
Button(action: navigator.back) {
|
||||
Image(systemName: "arrow.left")
|
||||
.font(.system(size: 24))
|
||||
}
|
||||
.disabled(navigator.backStack.isEmpty)
|
||||
|
||||
Spacer()
|
||||
|
||||
Button(action: navigator.forward) {
|
||||
Image(systemName: "arrow.right")
|
||||
.font(.system(size: 24))
|
||||
}
|
||||
.disabled(navigator.forwardStack.isEmpty)
|
||||
|
||||
Spacer()
|
||||
|
||||
Button(action: navigator.reload) {
|
||||
Image(systemName: "arrow.clockwise")
|
||||
.font(.system(size: 24))
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
Button(action: shareCurrentURL) {
|
||||
Image(systemName: "square.and.arrow.up")
|
||||
.font(.system(size: 24))
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
Button(action: {
|
||||
showPreferencesSheet = true
|
||||
}, label: {
|
||||
Image(systemName: "gear")
|
||||
.font(.system(size: 24))
|
||||
})
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
|
@ -100,6 +112,6 @@ struct ContentView: View {
|
|||
|
||||
struct ContentView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ContentView(navigator: NavigationManager(url: URL(string: "gemini://localhost/overview.gmi")!))
|
||||
ContentView(navigator: NavigationManager(url: URL(string: "gemini://localhost/overview.gmi")!), shareCurrentURL: {})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
|||
navigationManager.delegate = self
|
||||
|
||||
// Create the SwiftUI view that provides the window contents.
|
||||
let contentView = ContentView(navigator: navigationManager)
|
||||
let contentView = ContentView(navigator: navigationManager, shareCurrentURL: self.shareCurrentURL)
|
||||
|
||||
// Use a UIHostingController as window root view controller.
|
||||
if let windowScene = scene as? UIWindowScene {
|
||||
|
@ -62,7 +62,11 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
|||
// Use this method to save data, release shared resources, and store enough scene-specific state information
|
||||
// to restore the scene back to its current state.
|
||||
}
|
||||
|
||||
|
||||
private func shareCurrentURL() {
|
||||
let vc = UIActivityViewController(activityItems: [navigationManager.currentURL], applicationActivities: nil)
|
||||
window?.rootViewController?.present(vc, animated: true)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue