Skip to content

Commit e2e120f

Browse files
authored
Merge pull request #250 from hotwired/lazy-load-tabs-setting-move
Move `lazyLoadTabs` from `Hotwire.config` to `HotwireTabBarController` initializer
2 parents bc57aa1 + 5fd92af commit e2e120f

3 files changed

Lines changed: 23 additions & 14 deletions

File tree

‎Demo/AppDelegate.swift‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
4242
Hotwire.config.backButtonDisplayMode = .minimal
4343
Hotwire.config.showDoneButtonOnModals = true
4444
Hotwire.config.animateReplaceActions = true
45-
Hotwire.config.lazyLoadTabs = true
4645
#if DEBUG
4746
Hotwire.config.debugLoggingEnabled = true
4847
#endif

‎Source/HotwireConfig.swift‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,6 @@ public struct HotwireConfig {
2929
/// Set to `true` to fade content when performing a `replace` visit.
3030
public var animateReplaceActions = false
3131

32-
/// Controls when tab navigators perform their initial visit in `HotwireTabBarController`.
33-
///
34-
/// When `true`, only the initially selected tab starts when tabs are loaded; each
35-
/// remaining tab starts the first time the user selects it. When `false`, every
36-
/// tab starts immediately when `HotwireTabBarController.load(_:)` is called.
37-
///
38-
/// This affects when each tab's content is loaded, not whether the tab's
39-
/// navigator is created.
40-
public var lazyLoadTabs = true
41-
4232
/// Timeout (in seconds) for the request that resolves redirects before a visit.
4333
public var redirectResolutionTimeout: TimeInterval = 30
4434

‎Source/Turbo/ViewControllers/HotwireTabBarController.swift‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,35 @@ import UIKit
44
///
55
/// This controller loads tabs defined by `HotwireTab` and configures each one with its own `Navigator`.
66
/// The currently selected tab's navigator is exposed via the `activeNavigator` property.
7+
///
8+
/// By default, tabs are loaded lazily: only the initially selected tab performs its initial
9+
/// visit when `load(_:)` is called, and each remaining tab performs its initial visit the
10+
/// first time the user selects it. Pass `lazyLoadTabs: false` in the initializer to load
11+
/// every tab immediately instead.
712
open class HotwireTabBarController: UITabBarController, NavigationHandler {
8-
public init(navigatorDelegate: NavigatorDelegate? = nil) {
13+
/// Creates a tab bar controller.
14+
///
15+
/// - Parameters:
16+
/// - navigatorDelegate: An optional delegate for each tab's `Navigator`.
17+
/// - lazyLoadTabs: Controls when tab navigators perform their initial visit.
18+
/// When `true` (the default), only the initially selected tab starts when tabs
19+
/// are loaded; each remaining tab starts the first time the user selects it.
20+
/// When `false`, every tab starts immediately when `load(_:)` is called.
21+
/// This affects when each tab's content is loaded, not whether the tab's
22+
/// navigator is created.
23+
public init(
24+
navigatorDelegate: NavigatorDelegate? = nil,
25+
lazyLoadTabs: Bool = true
26+
) {
927
self.navigatorDelegate = navigatorDelegate
28+
self.lazyLoadTabs = lazyLoadTabs
1029
super.init(nibName: nil, bundle: nil)
1130
delegate = self
1231
}
1332

1433
@available(*, unavailable)
1534
public required init?(coder: NSCoder) {
16-
fatalError("Use init(navigatorDelegate:) instead.")
35+
fatalError("Use init(navigatorDelegate:lazyLoadTabs:) instead.")
1736
}
1837

1938
/// The active navigator corresponding to the currently selected tab.
@@ -38,7 +57,7 @@ open class HotwireTabBarController: UITabBarController, NavigationHandler {
3857
hotwireTabs = tabs
3958
setupTabs()
4059

41-
if Hotwire.config.lazyLoadTabs {
60+
if lazyLoadTabs {
4261
activeNavigator.start()
4362
} else {
4463
navigatorsByIdentifier.values.forEach { $0.start() }
@@ -69,6 +88,7 @@ open class HotwireTabBarController: UITabBarController, NavigationHandler {
6988
private var hotwireTabs: [HotwireTab] = []
7089
private var navigatorsByIdentifier: [HotwireTab.ID: Navigator] = [:]
7190
private let navigatorDelegate: NavigatorDelegate?
91+
private let lazyLoadTabs: Bool
7292

7393
/// Configures each tab for the appropriate platform API.
7494
private func setupTabs() {

0 commit comments

Comments
 (0)