Skip to content

Commit 4afda2d

Browse files
committed
Load Reader lazily
1 parent 2d4b58e commit 4afda2d

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

WordPress/Classes/System/ReaderPresenter.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class ReaderPresenter: NSObject, SplitViewDisplayable {
1414
var secondary: UINavigationController
1515

1616
/// The navigation controller for the main content when shown using tabs.
17-
private let mainNavigationController = UINavigationController()
17+
private var mainNavigationController = UINavigationController()
1818
private var latestContentVC: UIViewController?
1919

2020
private var viewContext: NSManagedObjectContext {
@@ -37,12 +37,14 @@ final class ReaderPresenter: NSObject, SplitViewDisplayable {
3737

3838
// TODO: (reader) update to allow seamless transitions between split view and tabs
3939
@objc func prepareForTabBarPresentation() -> UINavigationController {
40+
sidebar.onViewDidLoad = { [weak self] in
41+
self?.showInitialSelection()
42+
}
4043
sidebarViewModel.isCompact = true
4144
sidebarViewModel.restoreSelection(defaultValue: nil)
4245
mainNavigationController.navigationBar.prefersLargeTitles = true
43-
mainNavigationController.viewControllers = [sidebar]
46+
mainNavigationController = UINavigationController(rootViewController: sidebar) // Loads sidebar lazily
4447
sidebar.navigationItem.backButtonDisplayMode = .minimal
45-
showInitialSelection()
4648
return mainNavigationController
4749
}
4850

WordPress/Classes/ViewRelated/Reader/ReaderSidebarViewController.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ final class ReaderSidebarViewController: UIHostingController<AnyView> {
99
private var viewContext: NSManagedObjectContext { ContextManager.shared.mainContext }
1010
var didAppear = false
1111

12+
var onViewDidLoad: (() -> Void)?
13+
1214
init(viewModel: ReaderSidebarViewModel) {
1315
self.viewModel = viewModel
1416
// - warning: The `managedObjectContext` has to be set here in order for
@@ -25,6 +27,12 @@ final class ReaderSidebarViewController: UIHostingController<AnyView> {
2527
fatalError("init(coder:) has not been implemented")
2628
}
2729

30+
override func viewDidLoad() {
31+
super.viewDidLoad()
32+
33+
onViewDidLoad?()
34+
}
35+
2836
override func viewWillAppear(_ animated: Bool) {
2937
super.viewWillAppear(animated)
3038

0 commit comments

Comments
 (0)