Initial support for three pane mode
This commit is contained in:
parent
871ccbd728
commit
1ddf4189d3
|
@ -34,12 +34,16 @@ class AppCoordinator: NSObject, UndoableCommandRunner {
|
|||
private var masterTimelineViewController: MasterTimelineViewController?
|
||||
|
||||
private var detailViewController: DetailViewController? {
|
||||
if let detailNavController = rootSplitViewController.viewControllers.last as? UINavigationController {
|
||||
if let detailNavController = targetSplitForDetail().viewControllers.last as? UINavigationController {
|
||||
return detailNavController.topViewController as? DetailViewController
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
private var isThreePane: Bool {
|
||||
return rootSplitViewController.traitCollection.horizontalSizeClass == .regular
|
||||
}
|
||||
|
||||
private let fetchAndMergeArticlesQueue = CoalescingQueue(name: "Fetch and Merge Articles", interval: 0.5)
|
||||
|
||||
private var articleRowMap = [String: Int]() // articleID: rowIndex
|
||||
|
@ -182,8 +186,7 @@ class AppCoordinator: NSObject, UndoableCommandRunner {
|
|||
return appDelegate.unreadCount > 0
|
||||
}
|
||||
|
||||
init(_ rootSplitViewController: UISplitViewController) {
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
for section in treeController.rootNode.childNodes {
|
||||
|
@ -201,18 +204,19 @@ class AppCoordinator: NSObject, UndoableCommandRunner {
|
|||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(userDefaultsDidChange(_:)), name: UserDefaults.didChangeNotification, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(accountDidDownloadArticles(_:)), name: .AccountDidDownloadArticles, object: nil)
|
||||
|
||||
self.rootSplitViewController = rootSplitViewController
|
||||
}
|
||||
|
||||
func start() -> UIViewController {
|
||||
rootSplitViewController = UISplitViewController.template()
|
||||
rootSplitViewController.delegate = self
|
||||
|
||||
masterNavigationController = (rootSplitViewController.viewControllers.first as! UINavigationController)
|
||||
masterNavigationController.delegate = self
|
||||
masterFeedViewController = (masterNavigationController.topViewController as! MasterFeedViewController)
|
||||
masterFeedViewController = UIStoryboard.main.instantiateController(ofType: MasterFeedViewController.self)
|
||||
masterFeedViewController.coordinator = self
|
||||
masterNavigationController.pushViewController(masterFeedViewController, animated: false)
|
||||
|
||||
let systemMessageNavController = (rootSplitViewController.viewControllers.last as! UINavigationController)
|
||||
systemMessageNavController.topViewController!.navigationItem.leftBarButtonItem = rootSplitViewController.displayModeButtonItem
|
||||
|
||||
return rootSplitViewController
|
||||
}
|
||||
|
||||
// MARK: Notifications
|
||||
|
@ -422,7 +426,6 @@ class AppCoordinator: NSObject, UndoableCommandRunner {
|
|||
}
|
||||
|
||||
func indexesForArticleIDs(_ articleIDs: Set<String>) -> IndexSet {
|
||||
|
||||
var indexes = IndexSet()
|
||||
|
||||
articleIDs.forEach { (articleID) in
|
||||
|
@ -441,22 +444,21 @@ class AppCoordinator: NSObject, UndoableCommandRunner {
|
|||
masterTimelineViewController = UIStoryboard.main.instantiateController(ofType: MasterTimelineViewController.self)
|
||||
masterTimelineViewController!.coordinator = self
|
||||
currentMasterIndexPath = indexPath
|
||||
masterNavigationController.pushViewController(masterTimelineViewController!, animated: true)
|
||||
navControllerForTimeline().pushViewController(masterTimelineViewController!, animated: true)
|
||||
}
|
||||
|
||||
func selectArticle(_ indexPath: IndexPath) {
|
||||
if let detailNavigationController = rootSplitViewController.viewControllers.last as? UINavigationController,
|
||||
let _ = detailNavigationController.topViewController as? DetailViewController {
|
||||
if detailViewController != nil {
|
||||
currentArticleIndexPath = indexPath
|
||||
} else {
|
||||
let detailNavigationController = UIStoryboard.main.instantiateViewController(identifier: "DetailNavigationController") as! UINavigationController
|
||||
let detailViewController = detailNavigationController.topViewController as! DetailViewController
|
||||
let targetSplit = targetSplitForDetail()
|
||||
let detailViewController = UIStoryboard.main.instantiateController(ofType: DetailViewController.self)
|
||||
detailViewController.coordinator = self
|
||||
detailViewController.navigationItem.leftBarButtonItem = rootSplitViewController.displayModeButtonItem
|
||||
detailViewController.navigationItem.leftBarButtonItem = targetSplit.displayModeButtonItem
|
||||
detailViewController.navigationItem.leftItemsSupplementBackButton = true
|
||||
currentArticleIndexPath = indexPath
|
||||
// rootSplitViewController.toggleMasterView()
|
||||
rootSplitViewController.showDetailViewController(detailNavigationController, sender: self)
|
||||
targetSplit.showDetailViewController(detailViewController, sender: self)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -572,12 +574,11 @@ class AppCoordinator: NSObject, UndoableCommandRunner {
|
|||
extension AppCoordinator: UINavigationControllerDelegate {
|
||||
|
||||
func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
|
||||
if navigationController.viewControllers.count == 1 {
|
||||
let systemMessageNavController = UIStoryboard.main.instantiateViewController(identifier: "SystemMessageNavigationController") as! UINavigationController
|
||||
let systemMessageViewController = systemMessageNavController.topViewController as! SystemMessageViewController
|
||||
if isThreePane && navigationController.viewControllers.count == 1 {
|
||||
let systemMessageViewController = UIStoryboard.main.instantiateController(ofType: SystemMessageViewController.self)
|
||||
systemMessageViewController.navigationItem.leftBarButtonItem = rootSplitViewController.displayModeButtonItem
|
||||
systemMessageViewController.navigationItem.leftItemsSupplementBackButton = true
|
||||
rootSplitViewController.showDetailViewController(systemMessageNavController, sender: self)
|
||||
rootSplitViewController.showDetailViewController(systemMessageViewController, sender: self)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -817,4 +818,35 @@ private extension AppCoordinator {
|
|||
|
||||
}
|
||||
|
||||
// MARK: Double Split
|
||||
|
||||
func ensureDoubleSplit() -> UISplitViewController {
|
||||
if let subSplit = rootSplitViewController.viewControllers.last as? UISplitViewController {
|
||||
return subSplit
|
||||
}
|
||||
|
||||
let subSplit = UISplitViewController.template()
|
||||
subSplit.delegate = self
|
||||
subSplit.preferredPrimaryColumnWidthFraction = 0.5
|
||||
rootSplitViewController.showDetailViewController(subSplit, sender: self)
|
||||
return subSplit
|
||||
}
|
||||
|
||||
func navControllerForTimeline() -> UINavigationController {
|
||||
if isThreePane {
|
||||
let subSplit = ensureDoubleSplit()
|
||||
return subSplit.viewControllers.first as! UINavigationController
|
||||
} else {
|
||||
return masterNavigationController
|
||||
}
|
||||
}
|
||||
|
||||
func targetSplitForDetail() -> UISplitViewController {
|
||||
if isThreePane {
|
||||
return ensureDoubleSplit()
|
||||
} else {
|
||||
return rootSplitViewController
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<wkWebView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="t8d-md-Yhc">
|
||||
<rect key="frame" x="0.0" y="88" width="414" height="725"/>
|
||||
<rect key="frame" x="0.0" y="44" width="414" height="769"/>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<wkWebViewConfiguration key="configuration">
|
||||
<audiovisualMediaTypes key="mediaTypesRequiringUserActionForPlayback" none="YES"/>
|
||||
|
@ -137,23 +137,7 @@
|
|||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="FJe-Yq-33r" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="2367" y="-83"/>
|
||||
</scene>
|
||||
<!--Navigation Controller-->
|
||||
<scene sceneID="MFb-g9-xHT">
|
||||
<objects>
|
||||
<navigationController storyboardIdentifier="SystemMessageNavigationController" id="mTc-f9-2dr" sceneMemberID="viewController">
|
||||
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="Ork-ch-DOU">
|
||||
<rect key="frame" x="0.0" y="44" width="414" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</navigationBar>
|
||||
<connections>
|
||||
<segue destination="Xld-e9-xoL" kind="relationship" relationship="rootViewController" id="E2B-jI-ffd"/>
|
||||
</connections>
|
||||
</navigationController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="WCE-Jg-o7b" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="154" y="-83"/>
|
||||
<point key="canvasLocation" x="1043" y="-70"/>
|
||||
</scene>
|
||||
<!--System Message-->
|
||||
<scene sceneID="tbo-yR-QVH">
|
||||
|
@ -185,7 +169,7 @@
|
|||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="rgH-br-nLG" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="874" y="-83"/>
|
||||
<point key="canvasLocation" x="154" y="-70"/>
|
||||
</scene>
|
||||
<!--Timeline-->
|
||||
<scene sceneID="fag-XH-avP">
|
||||
|
@ -241,7 +225,7 @@
|
|||
<toolbarItems/>
|
||||
<connections>
|
||||
<segue destination="RMx-3f-FxP" kind="relationship" relationship="masterViewController" id="BlO-5A-QYV"/>
|
||||
<segue destination="mTc-f9-2dr" kind="relationship" relationship="detailViewController" id="3HU-Sb-w7Y"/>
|
||||
<segue destination="Xld-e9-xoL" kind="relationship" relationship="detailViewController" id="oRP-0C-oPK"/>
|
||||
</connections>
|
||||
</splitViewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="cZU-Oi-B1e" sceneMemberID="firstResponder"/>
|
||||
|
@ -299,26 +283,6 @@
|
|||
</objects>
|
||||
<point key="canvasLocation" x="900" y="-759"/>
|
||||
</scene>
|
||||
<!--Navigation Controller-->
|
||||
<scene sceneID="r7l-gg-dq7">
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="SLD-UC-DBI" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
<navigationController storyboardIdentifier="DetailNavigationController" useStoryboardIdentifierAsRestorationIdentifier="YES" toolbarHidden="NO" id="vC3-pB-5Vb" sceneMemberID="viewController">
|
||||
<navigationBar key="navigationBar" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="DjV-YW-jjY">
|
||||
<rect key="frame" x="0.0" y="44" width="414" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</navigationBar>
|
||||
<toolbar key="toolbar" opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="Skn-vK-czG">
|
||||
<rect key="frame" x="0.0" y="813" width="414" height="49"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</toolbar>
|
||||
<connections>
|
||||
<segue destination="JEX-9P-axG" kind="relationship" relationship="rootViewController" id="yH5-Bf-My9"/>
|
||||
</connections>
|
||||
</navigationController>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="1619" y="-83"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
<resources>
|
||||
<image name="arrow.down" catalog="system" width="58" height="64"/>
|
||||
|
|
|
@ -13,7 +13,11 @@ extension UISplitViewController {
|
|||
static func template() -> UISplitViewController {
|
||||
let splitViewController = UISplitViewController()
|
||||
splitViewController.preferredDisplayMode = .allVisible
|
||||
splitViewController.viewControllers = [UINavigationController()]
|
||||
|
||||
let navController = UINavigationController()
|
||||
navController.isToolbarHidden = false
|
||||
splitViewController.viewControllers = [navController]
|
||||
|
||||
return splitViewController
|
||||
}
|
||||
|
||||
|
|
|
@ -11,14 +11,14 @@ import UIKit
|
|||
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||
|
||||
var window: UIWindow?
|
||||
var coordinator: AppCoordinator?
|
||||
var coordinator = AppCoordinator()
|
||||
|
||||
// UIWindowScene delegate
|
||||
|
||||
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
|
||||
|
||||
window!.tintColor = AppAssets.netNewsWireBlueColor
|
||||
coordinator = AppCoordinator(window!.rootViewController as! UISplitViewController)
|
||||
window?.rootViewController = coordinator.start()
|
||||
|
||||
// if let userActivity = connectionOptions.userActivities.first ?? session.stateRestorationActivity {
|
||||
// if !configure(window: window, with: userActivity) {
|
||||
|
|
Loading…
Reference in New Issue