Implement Add NNW news in the settings
This commit is contained in:
parent
8e939e9942
commit
e2816cba7a
|
@ -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 }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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!)!)
|
||||
|
|
Loading…
Reference in New Issue