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
|
@ObservedObject private var navigator: NavigationManager
|
||||||
@State private var urlFieldContents: String
|
@State private var urlFieldContents: String
|
||||||
@State private var showPreferencesSheet = false
|
@State private var showPreferencesSheet = false
|
||||||
|
private let shareCurrentURL: () -> Void
|
||||||
|
|
||||||
init(navigator: NavigationManager) {
|
init(navigator: NavigationManager, shareCurrentURL: @escaping () -> Void) {
|
||||||
self.navigator = navigator
|
self.navigator = navigator
|
||||||
self._urlFieldContents = State(initialValue: navigator.currentURL.absoluteString)
|
self._urlFieldContents = State(initialValue: navigator.currentURL.absoluteString)
|
||||||
|
self.shareCurrentURL = shareCurrentURL
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
@ -55,28 +57,37 @@ struct ContentView: View {
|
||||||
|
|
||||||
private var bottomBar: some View {
|
private var bottomBar: some View {
|
||||||
HStack {
|
HStack {
|
||||||
|
// use a group because this exceeds the 10 view limit :/
|
||||||
|
Group {
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
Button(action: navigator.back, label: {
|
Button(action: navigator.back) {
|
||||||
Image(systemName: "arrow.left")
|
Image(systemName: "arrow.left")
|
||||||
.font(.system(size: 24))
|
.font(.system(size: 24))
|
||||||
})
|
}
|
||||||
.disabled(navigator.backStack.isEmpty)
|
.disabled(navigator.backStack.isEmpty)
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
Button(action: navigator.forward, label: {
|
Button(action: navigator.forward) {
|
||||||
Image(systemName: "arrow.right")
|
Image(systemName: "arrow.right")
|
||||||
.font(.system(size: 24))
|
.font(.system(size: 24))
|
||||||
})
|
}
|
||||||
.disabled(navigator.forwardStack.isEmpty)
|
.disabled(navigator.forwardStack.isEmpty)
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
Button(action: navigator.reload, label: {
|
Button(action: navigator.reload) {
|
||||||
Image(systemName: "arrow.clockwise")
|
Image(systemName: "arrow.clockwise")
|
||||||
.font(.system(size: 24))
|
.font(.system(size: 24))
|
||||||
})
|
}
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
Button(action: shareCurrentURL) {
|
||||||
|
Image(systemName: "square.and.arrow.up")
|
||||||
|
.font(.system(size: 24))
|
||||||
|
}
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
|
@ -86,6 +97,7 @@ struct ContentView: View {
|
||||||
Image(systemName: "gear")
|
Image(systemName: "gear")
|
||||||
.font(.system(size: 24))
|
.font(.system(size: 24))
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
}
|
}
|
||||||
|
@ -100,6 +112,6 @@ struct ContentView: View {
|
||||||
|
|
||||||
struct ContentView_Previews: PreviewProvider {
|
struct ContentView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
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
|
navigationManager.delegate = self
|
||||||
|
|
||||||
// Create the SwiftUI view that provides the window contents.
|
// 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.
|
// Use a UIHostingController as window root view controller.
|
||||||
if let windowScene = scene as? UIWindowScene {
|
if let windowScene = scene as? UIWindowScene {
|
||||||
|
@ -63,6 +63,10 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||||
// to restore the scene back to its current state.
|
// 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