iOS: Fix crash showing share sheet on iPad
This commit is contained in:
parent
364ffe9f94
commit
203bd1804f
|
@ -0,0 +1,24 @@
|
|||
//
|
||||
// ActivityView.swift
|
||||
// Gemini-iOS
|
||||
//
|
||||
// Created by Shadowfacts on 9/30/20.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ActivityView: UIViewControllerRepresentable {
|
||||
typealias UIViewControllerType = UIActivityViewController
|
||||
|
||||
let items: [Any]
|
||||
let activities: [UIActivity]?
|
||||
|
||||
func makeUIViewController(context: Context) -> UIActivityViewController {
|
||||
return UIActivityViewController(activityItems: items, applicationActivities: activities)
|
||||
}
|
||||
|
||||
func updateUIViewController(_ uiViewController: UIActivityViewController, context: Context) {
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -81,10 +81,7 @@ class BrowserViewController: UIViewController, UIScrollViewDelegate {
|
|||
navBarHost.view.topAnchor.constraint(equalTo: view.topAnchor),
|
||||
])
|
||||
|
||||
toolBarHost = UIHostingController(rootView: ToolBar(navigator: navigator, shareCurrentURL: {
|
||||
let vc = UIActivityViewController(activityItems: [self.navigator.currentURL], applicationActivities: nil)
|
||||
self.present(vc, animated: true)
|
||||
}))
|
||||
toolBarHost = UIHostingController(rootView: ToolBar(navigator: navigator))
|
||||
toolBarHost.view.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(toolBarHost.view)
|
||||
addChild(toolBarHost)
|
||||
|
|
|
@ -11,7 +11,6 @@ import BrowserCore
|
|||
struct ContentView: View {
|
||||
@ObservedObject private var navigator: NavigationManager
|
||||
@State private var urlFieldContents: String
|
||||
private let shareCurrentURL: () -> Void
|
||||
@State private var prevScrollOffset: CGFloat = 0
|
||||
@State private var scrollOffset: CGFloat = 0 {
|
||||
didSet {
|
||||
|
@ -21,11 +20,11 @@ struct ContentView: View {
|
|||
@State private var barOffset: CGFloat = 0
|
||||
@State private var navBarHeight: CGFloat = 0
|
||||
@State private var toolBarHeight: CGFloat = 0
|
||||
@State private var showShareSheet = false
|
||||
|
||||
init(navigator: NavigationManager, shareCurrentURL: @escaping () -> Void) {
|
||||
init(navigator: NavigationManager) {
|
||||
self.navigator = navigator
|
||||
self._urlFieldContents = State(initialValue: navigator.currentURL.absoluteString)
|
||||
self.shareCurrentURL = shareCurrentURL
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
|
@ -71,7 +70,7 @@ struct ContentView: View {
|
|||
|
||||
Spacer()
|
||||
|
||||
ToolBar(navigator: navigator, shareCurrentURL: shareCurrentURL)
|
||||
ToolBar(navigator: navigator, showShareSheet: $showShareSheet)
|
||||
.background(GeometryReader { (geom: GeometryProxy) in
|
||||
Color.clear.preference(key: ToolBarHeightPrefKey.self, value: geom.frame(in: .global).height)
|
||||
})
|
||||
|
@ -90,6 +89,9 @@ struct ContentView: View {
|
|||
.onReceive(navigator.$currentURL, perform: { (new) in
|
||||
urlFieldContents = new.absoluteString
|
||||
})
|
||||
.sheet(isPresented: $showShareSheet) {
|
||||
ActivityView(items: [navigator.currentURL], activities: nil)
|
||||
}
|
||||
}
|
||||
|
||||
private func tweakAppearance() {
|
||||
|
@ -132,6 +134,6 @@ fileprivate enum ScrollDirection {
|
|||
|
||||
struct ContentView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ContentView(navigator: NavigationManager(url: URL(string: "gemini://localhost/overview.gmi")!), shareCurrentURL: {})
|
||||
ContentView(navigator: NavigationManager(url: URL(string: "gemini://localhost/overview.gmi")!))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import SwiftUI
|
|||
struct PreferencesView: View {
|
||||
@ObservedObject var preferences: Preferences = .shared
|
||||
|
||||
@Binding var presented: Bool
|
||||
@Environment(\.presentationMode) @Binding var presentationMode: PresentationMode
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
|
@ -30,7 +30,7 @@ struct PreferencesView: View {
|
|||
|
||||
private var doneButton: some View {
|
||||
Button(action: {
|
||||
presented = false
|
||||
presentationMode.dismiss()
|
||||
}, label: {
|
||||
Text("Done")
|
||||
})
|
||||
|
@ -72,6 +72,6 @@ struct PreferencesView_Previews: PreviewProvider {
|
|||
@State static var presented = true
|
||||
|
||||
static var previews: some View {
|
||||
PreferencesView(presented: $presented)
|
||||
PreferencesView()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
|||
navigationManager.delegate = self
|
||||
|
||||
// Create the SwiftUI view that provides the window contents.
|
||||
let contentView = ContentView(navigator: navigationManager, shareCurrentURL: self.shareCurrentURL)
|
||||
let contentView = ContentView(navigator: navigationManager)
|
||||
|
||||
// Use a UIHostingController as window root view controller.
|
||||
if let windowScene = scene as? UIWindowScene {
|
||||
|
@ -92,11 +92,6 @@ 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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import BrowserCore
|
|||
|
||||
struct ToolBar: View {
|
||||
@ObservedObject var navigator: NavigationManager
|
||||
let shareCurrentURL: () -> Void
|
||||
@Binding var showShareSheet: Bool
|
||||
@State private var showPreferencesSheet = false
|
||||
|
||||
@Environment(\.colorScheme) var colorScheme: ColorScheme
|
||||
|
@ -73,7 +73,9 @@ struct ToolBar: View {
|
|||
|
||||
Spacer()
|
||||
|
||||
Button(action: shareCurrentURL) {
|
||||
Button {
|
||||
showShareSheet = true
|
||||
} label: {
|
||||
Image(systemName: "square.and.arrow.up")
|
||||
.font(.system(size: 24))
|
||||
}
|
||||
|
@ -99,7 +101,7 @@ struct ToolBar: View {
|
|||
.padding(.bottom, 4)
|
||||
.background(Color(UIColor.systemBackground).edgesIgnoringSafeArea(.bottom))
|
||||
.sheet(isPresented: $showPreferencesSheet, content: {
|
||||
PreferencesView(presented: $showPreferencesSheet)
|
||||
PreferencesView()
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -115,7 +117,9 @@ struct ToolBar: View {
|
|||
}
|
||||
|
||||
struct ToolBar_Previews: PreviewProvider {
|
||||
@State private static var showShareSheet = false
|
||||
|
||||
static var previews: some View {
|
||||
ToolBar(navigator: NavigationManager(url: URL(string: "gemini://localhost/overview.gmi")!), shareCurrentURL: {})
|
||||
ToolBar(navigator: NavigationManager(url: URL(string: "gemini://localhost/overview.gmi")!), showShareSheet: $showShareSheet)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,12 +36,12 @@
|
|||
D62664EE24BC0BCE00DF9B88 /* MaybeLazyVStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = D62664ED24BC0BCE00DF9B88 /* MaybeLazyVStack.swift */; };
|
||||
D62664F024BC0D7700DF9B88 /* GeminiFormat.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D62664A824BBF26A00DF9B88 /* GeminiFormat.framework */; };
|
||||
D62664FA24BC12BC00DF9B88 /* DocumentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D62664F924BC12BC00DF9B88 /* DocumentTests.swift */; };
|
||||
D62BCEE2252553620031D894 /* ActivityView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D62BCEE1252553620031D894 /* ActivityView.swift */; };
|
||||
D664673624BD07F700B0B741 /* RenderingBlock.swift in Sources */ = {isa = PBXBuildFile; fileRef = D664673524BD07F700B0B741 /* RenderingBlock.swift */; };
|
||||
D664673824BD086F00B0B741 /* RenderingBlockView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D664673724BD086F00B0B741 /* RenderingBlockView.swift */; };
|
||||
D664673A24BD0B8E00B0B741 /* Fonts.swift in Sources */ = {isa = PBXBuildFile; fileRef = D664673924BD0B8E00B0B741 /* Fonts.swift */; };
|
||||
D691A64E25217C6F00348C4B /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = D691A64D25217C6F00348C4B /* Preferences.swift */; };
|
||||
D691A66725217FD800348C4B /* PreferencesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D691A66625217FD800348C4B /* PreferencesView.swift */; };
|
||||
D691A6772522382E00348C4B /* BrowserViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D691A6762522382E00348C4B /* BrowserViewController.swift */; };
|
||||
D691A68725223A4700348C4B /* NavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = D691A68625223A4600348C4B /* NavigationBar.swift */; };
|
||||
D691A6A0252242FC00348C4B /* ToolBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = D691A69F252242FC00348C4B /* ToolBar.swift */; };
|
||||
D69F00AC24BE9DD300E37622 /* GeminiDataTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = D69F00AB24BE9DD300E37622 /* GeminiDataTask.swift */; };
|
||||
|
@ -294,6 +294,7 @@
|
|||
D62664EB24BC0B4D00DF9B88 /* DocumentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DocumentView.swift; sourceTree = "<group>"; };
|
||||
D62664ED24BC0BCE00DF9B88 /* MaybeLazyVStack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MaybeLazyVStack.swift; sourceTree = "<group>"; };
|
||||
D62664F924BC12BC00DF9B88 /* DocumentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DocumentTests.swift; sourceTree = "<group>"; };
|
||||
D62BCEE1252553620031D894 /* ActivityView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityView.swift; sourceTree = "<group>"; };
|
||||
D664673524BD07F700B0B741 /* RenderingBlock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RenderingBlock.swift; sourceTree = "<group>"; };
|
||||
D664673724BD086F00B0B741 /* RenderingBlockView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RenderingBlockView.swift; sourceTree = "<group>"; };
|
||||
D664673924BD0B8E00B0B741 /* Fonts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Fonts.swift; sourceTree = "<group>"; };
|
||||
|
@ -560,6 +561,7 @@
|
|||
D691A69F252242FC00348C4B /* ToolBar.swift */,
|
||||
D691A64D25217C6F00348C4B /* Preferences.swift */,
|
||||
D691A66625217FD800348C4B /* PreferencesView.swift */,
|
||||
D62BCEE1252553620031D894 /* ActivityView.swift */,
|
||||
D6E152AA24BFFDF600FDF9D3 /* Assets.xcassets */,
|
||||
D6E152AF24BFFDF600FDF9D3 /* LaunchScreen.storyboard */,
|
||||
D6E152B224BFFDF600FDF9D3 /* Info.plist */,
|
||||
|
@ -1063,10 +1065,10 @@
|
|||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
D691A66725217FD800348C4B /* PreferencesView.swift in Sources */,
|
||||
D691A6772522382E00348C4B /* BrowserViewController.swift in Sources */,
|
||||
D6E152A524BFFDF500FDF9D3 /* AppDelegate.swift in Sources */,
|
||||
D691A6A0252242FC00348C4B /* ToolBar.swift in Sources */,
|
||||
D6E152A724BFFDF500FDF9D3 /* SceneDelegate.swift in Sources */,
|
||||
D62BCEE2252553620031D894 /* ActivityView.swift in Sources */,
|
||||
D691A68725223A4700348C4B /* NavigationBar.swift in Sources */,
|
||||
D691A64E25217C6F00348C4B /* Preferences.swift in Sources */,
|
||||
D6E152A924BFFDF500FDF9D3 /* ContentView.swift in Sources */,
|
||||
|
|
|
@ -27,12 +27,12 @@
|
|||
<key>GeminiProtocol.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>3</integer>
|
||||
<integer>4</integer>
|
||||
</dict>
|
||||
<key>GeminiRenderer.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>4</integer>
|
||||
<integer>3</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>SuppressBuildableAutocreation</key>
|
||||
|
|
Loading…
Reference in New Issue