@@ -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.
712open 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