mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Remove toolbar autohiding and add optional fullscreen mode.
This commit is contained in:
77
iOS/UIKit Extensions/InteractiveNavigationController.swift
Normal file
77
iOS/UIKit Extensions/InteractiveNavigationController.swift
Normal file
@@ -0,0 +1,77 @@
|
||||
//
|
||||
// InteractiveNavigationController.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Maurice Parker on 8/22/19.
|
||||
// Copyright © 2019 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
protocol InteractiveNavigationControllerTappable {
|
||||
func didTapNavigationBar()
|
||||
}
|
||||
|
||||
class InteractiveNavigationController: UINavigationController {
|
||||
|
||||
private let poppableDelegate = PoppableGestureRecognizerDelegate()
|
||||
|
||||
static func template() -> UINavigationController {
|
||||
let navController = InteractiveNavigationController()
|
||||
navController.configure()
|
||||
return navController
|
||||
}
|
||||
|
||||
static func template(rootViewController: UIViewController) -> UINavigationController {
|
||||
let navController = InteractiveNavigationController(rootViewController: rootViewController)
|
||||
navController.configure()
|
||||
return navController
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
poppableDelegate.originalDelegate = interactivePopGestureRecognizer?.delegate
|
||||
poppableDelegate.navigationController = self
|
||||
interactivePopGestureRecognizer?.delegate = poppableDelegate
|
||||
|
||||
navigationBar.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didTapNavigationBar)))
|
||||
}
|
||||
|
||||
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
|
||||
super.traitCollectionDidChange(previousTraitCollection)
|
||||
if traitCollection.userInterfaceStyle != previousTraitCollection?.userInterfaceStyle {
|
||||
configure()
|
||||
}
|
||||
}
|
||||
|
||||
@objc func didTapNavigationBar() {
|
||||
if let tappable = topViewController as? InteractiveNavigationControllerTappable {
|
||||
tappable.didTapNavigationBar()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private extension InteractiveNavigationController {
|
||||
|
||||
func configure() {
|
||||
isToolbarHidden = false
|
||||
view.backgroundColor = AppAssets.barBackgroundColor
|
||||
|
||||
let navigationAppearance = UINavigationBarAppearance()
|
||||
navigationAppearance.backgroundColor = AppAssets.barBackgroundColor
|
||||
navigationAppearance.titleTextAttributes = [.foregroundColor: UIColor.label]
|
||||
navigationAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.label]
|
||||
navigationBar.standardAppearance = navigationAppearance
|
||||
navigationBar.tintColor = AppAssets.primaryAccentColor
|
||||
|
||||
let toolbarAppearance = UIToolbarAppearance()
|
||||
toolbarAppearance.backgroundColor = AppAssets.barBackgroundColor
|
||||
toolbar.standardAppearance = toolbarAppearance
|
||||
toolbar.compactAppearance = toolbarAppearance
|
||||
toolbar.tintColor = AppAssets.primaryAccentColor
|
||||
}
|
||||
|
||||
}
|
||||
40
iOS/UIKit Extensions/PoppableGestureRecognizerDelegate.swift
Normal file
40
iOS/UIKit Extensions/PoppableGestureRecognizerDelegate.swift
Normal file
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// PoppableGestureRecognizerDelegate.swift
|
||||
// NetNewsWire-iOS
|
||||
//
|
||||
// Created by Maurice Parker on 11/18/19.
|
||||
// Copyright © 2019 Ranchero Software. All rights reserved.
|
||||
//
|
||||
// https://stackoverflow.com/a/38042863
|
||||
|
||||
import UIKit
|
||||
|
||||
final class PoppableGestureRecognizerDelegate: NSObject, UIGestureRecognizerDelegate {
|
||||
|
||||
weak var navigationController: UINavigationController?
|
||||
weak var originalDelegate: UIGestureRecognizerDelegate?
|
||||
|
||||
override func responds(to aSelector: Selector!) -> Bool {
|
||||
if aSelector == #selector(gestureRecognizer(_:shouldReceive:)) {
|
||||
return true
|
||||
} else if let responds = originalDelegate?.responds(to: aSelector) {
|
||||
return responds
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
override func forwardingTarget(for aSelector: Selector!) -> Any? {
|
||||
return originalDelegate
|
||||
}
|
||||
|
||||
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
|
||||
if let nav = navigationController, nav.isNavigationBarHidden, nav.viewControllers.count > 1 {
|
||||
return true
|
||||
} else if let result = originalDelegate?.gestureRecognizer?(gestureRecognizer, shouldReceive: touch) {
|
||||
return result
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ extension UISplitViewController {
|
||||
static func template() -> UISplitViewController {
|
||||
let splitViewController = UISplitViewController()
|
||||
splitViewController.preferredDisplayMode = .automatic
|
||||
splitViewController.viewControllers = [ThemedNavigationController.template()]
|
||||
splitViewController.viewControllers = [InteractiveNavigationController.template()]
|
||||
return splitViewController
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user