diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 1c4dc99cd..0e088349e 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -771,23 +771,21 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { } func showSettings() { -// let settingsNavViewController = UIStoryboard.settings.instantiateInitialViewController() as! UINavigationController -// settingsNavViewController.modalPresentationStyle = .formSheet -// let settingsViewController = settingsNavViewController.topViewController as! SettingsViewController -// settingsViewController.presentingParentController = rootSplitViewController -// rootSplitViewController.present(settingsNavViewController, animated: true) - rootSplitViewController.present(style: .formSheet) { - SettingsView(viewModel: SettingsView.ViewModel()) + SettingsView(viewModel: SettingsView.ViewModel()).environment(\.sceneCoordinator, self) } } - func showAdd(_ type: AddControllerType) { + func showAdd(_ type: AddControllerType, initialFeed: String? = nil, initialFeedName: String? = nil) { selectFeed(nil) let addViewController = UIStoryboard.add.instantiateInitialViewController() as! UINavigationController + let containerController = addViewController.topViewController as! AddContainerViewController containerController.initialControllerType = type + containerController.initialFeed = initialFeed + containerController.initialFeedName = initialFeedName + addViewController.modalPresentationStyle = .formSheet addViewController.preferredContentSize = AddContainerViewController.preferredContentSizeForFormSheetDisplay masterFeedViewController.present(addViewController, animated: true) @@ -1627,3 +1625,20 @@ private extension SceneCoordinator { } } + +// MARK: SwiftUI + +struct SceneCoordinatorHolder { + weak var value: SceneCoordinator? +} + +struct SceneCoordinatorKey: EnvironmentKey { + static var defaultValue: SceneCoordinatorHolder { return SceneCoordinatorHolder(value: nil ) } +} + +extension EnvironmentValues { + var sceneCoordinator: SceneCoordinator? { + get { return self[SceneCoordinatorKey.self].value } + set { self[SceneCoordinatorKey.self].value = newValue } + } +} diff --git a/iOS/Settings/SettingsView.swift b/iOS/Settings/SettingsView.swift index 253530f66..a398a8033 100644 --- a/iOS/Settings/SettingsView.swift +++ b/iOS/Settings/SettingsView.swift @@ -15,6 +15,7 @@ struct SettingsView : View { @ObservedObject var viewModel: ViewModel @Environment(\.viewController) private var viewController: UIViewController? + @Environment(\.sceneCoordinator) private var coordinator: SceneCoordinator? @State private var isWebsitePresented: Bool = false @State private var website: String? = nil @@ -134,7 +135,16 @@ struct SettingsView : View { Text("How To Support NetNewsWire") }.foregroundColor(.primary) - Text("Add NetNewsWire News Feed") + if !AccountManager.shared.anyAccountHasFeedWithURL("https://nnw.ranchero.com/feed.json") { + Button(action: { + self.viewController?.dismiss(animated: true) { + let feedName = NSLocalizedString("NetNewsWire News", comment: "NetNewsWire News") + self.coordinator?.showAdd(.feed, initialFeed: "https://nnw.ranchero.com/feed.json", initialFeedName: feedName) + } + }) { + Text("Add NetNewsWire News Feed") + }.foregroundColor(.primary) + } }.sheet(isPresented: $isWebsitePresented) { SafariView(url: URL(string: self.website!)!)