From 3d9f407ae67f56595132dca7b10836e965109088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=A0vara?= Date: Fri, 6 Dec 2024 17:47:48 +0100 Subject: [PATCH 1/5] Move `registerBridgeComponents` to `AppDelegate`. --- Demo/AppDelegate.swift | 5 +++++ Demo/SceneController.swift | 10 ---------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Demo/AppDelegate.swift b/Demo/AppDelegate.swift index 52e889b..dcb8095 100644 --- a/Demo/AppDelegate.swift +++ b/Demo/AppDelegate.swift @@ -6,6 +6,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { Hotwire.config.backButtonDisplayMode = .minimal Hotwire.config.showDoneButtonOnModals = true + Hotwire.registerBridgeComponents([ + FormComponent.self, + MenuComponent.self, + OverflowMenuComponent.self, + ]) #if DEBUG Hotwire.config.debugLoggingEnabled = true diff --git a/Demo/SceneController.swift b/Demo/SceneController.swift index 5395504..7dec363 100644 --- a/Demo/SceneController.swift +++ b/Demo/SceneController.swift @@ -11,14 +11,6 @@ final class SceneController: UIResponder { // MARK: - Setup - private func configureBridge() { - Hotwire.registerBridgeComponents([ - FormComponent.self, - MenuComponent.self, - OverflowMenuComponent.self, - ]) - } - private func configureRootViewController() { guard let window = window else { fatalError() @@ -47,8 +39,6 @@ extension SceneController: UIWindowSceneDelegate { window = UIWindow(windowScene: windowScene) window?.makeKeyAndVisible() - - configureBridge() configureRootViewController() navigator.route(rootURL) From 2126da3a806b2777b9fa95caf9452b9069d5adbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=A0vara?= Date: Fri, 6 Dec 2024 18:35:23 +0100 Subject: [PATCH 2/5] Move `matchQueryStrings` to `PathConfiguration`. --- Source/HotwireConfig.swift | 8 -------- Source/Turbo/Path Configuration/PathConfiguration.swift | 4 ++++ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Source/HotwireConfig.swift b/Source/HotwireConfig.swift index b7ea101..f0c2733 100644 --- a/Source/HotwireConfig.swift +++ b/Source/HotwireConfig.swift @@ -78,11 +78,3 @@ public struct HotwireConfig { return configuration } } - -public extension HotwireConfig { - class PathConfiguration { - /// Enable to include the query string (in addition to the path) when applying rules. - /// Disable to only consider the path when applying rules. - public var matchQueryStrings = true - } -} diff --git a/Source/Turbo/Path Configuration/PathConfiguration.swift b/Source/Turbo/Path Configuration/PathConfiguration.swift index 8e2a484..4eb388a 100644 --- a/Source/Turbo/Path Configuration/PathConfiguration.swift +++ b/Source/Turbo/Path Configuration/PathConfiguration.swift @@ -20,6 +20,10 @@ public struct PathConfigurationLoaderOptions { public final class PathConfiguration { public weak var delegate: PathConfigurationDelegate? + /// Enable to include the query string (in addition to the path) when applying rules. + /// Disable to only consider the path when applying rules. + public var matchQueryStrings = true + /// Returns top-level settings: `{ settings: {} }` public private(set) var settings: [String: AnyHashable] = [:] From 91a19183a31b7b5bddf334b09694078df39278aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=A0vara?= Date: Fri, 6 Dec 2024 18:36:07 +0100 Subject: [PATCH 3/5] Add utility func to load path config to the Hotwire enum. --- Source/Hotwire.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Source/Hotwire.swift b/Source/Hotwire.swift index 432109e..0adba04 100644 --- a/Source/Hotwire.swift +++ b/Source/Hotwire.swift @@ -19,5 +19,14 @@ public enum Hotwire { } } + + /// Loads the `PathConfiguration` JSON file(s) from the provided sources + /// to configure navigation rules + /// - Parameter sources: An array of `PathConfiguration.Source` objects representing + /// the sources to load. + public static func loadPathConfiguration(from sources: [PathConfiguration.Source]) { + config.pathConfiguration.sources = sources + } + static var bridgeComponentTypes = [BridgeComponent.Type]() } From ade80c2f846bc7020e17aec5924019fd2cf93c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=A0vara?= Date: Fri, 6 Dec 2024 18:37:23 +0100 Subject: [PATCH 4/5] Consolidate all global config by moving it in app delegate. --- Demo/AppDelegate.swift | 34 ++++++++++++++++++++++------------ Demo/SceneController.swift | 20 ++------------------ 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/Demo/AppDelegate.swift b/Demo/AppDelegate.swift index dcb8095..41ec5c7 100644 --- a/Demo/AppDelegate.swift +++ b/Demo/AppDelegate.swift @@ -4,18 +4,7 @@ import UIKit @main class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { - Hotwire.config.backButtonDisplayMode = .minimal - Hotwire.config.showDoneButtonOnModals = true - Hotwire.registerBridgeComponents([ - FormComponent.self, - MenuComponent.self, - OverflowMenuComponent.self, - ]) - - #if DEBUG - Hotwire.config.debugLoggingEnabled = true - #endif - + configureHotwire() return true } @@ -24,4 +13,25 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) } + + private func configureHotwire() { + // Load the path configuration + Hotwire.loadPathConfiguration(from: [ + .file(Bundle.main.url(forResource: "path-configuration", withExtension: "json")!) + ]) + + // Register bridge components + Hotwire.registerBridgeComponents([ + FormComponent.self, + MenuComponent.self, + OverflowMenuComponent.self, + ]) + + // Set configuration options + Hotwire.config.backButtonDisplayMode = .minimal + Hotwire.config.showDoneButtonOnModals = true +#if DEBUG + Hotwire.config.debugLoggingEnabled = true +#endif + } } diff --git a/Demo/SceneController.swift b/Demo/SceneController.swift index 7dec363..a12d020 100644 --- a/Demo/SceneController.swift +++ b/Demo/SceneController.swift @@ -7,17 +7,7 @@ final class SceneController: UIResponder { var window: UIWindow? private let rootURL = Demo.current - private lazy var navigator = Navigator(pathConfiguration: pathConfiguration, delegate: self) - - // MARK: - Setup - - private func configureRootViewController() { - guard let window = window else { - fatalError() - } - - window.rootViewController = navigator.rootViewController - } + private lazy var navigator = Navigator(delegate: self) // MARK: - Authentication @@ -25,12 +15,6 @@ final class SceneController: UIResponder { let authURL = rootURL.appendingPathComponent("/signin") navigator.route(authURL) } - - // MARK: - Path Configuration - - private lazy var pathConfiguration = PathConfiguration(sources: [ - .file(Bundle.main.url(forResource: "path-configuration", withExtension: "json")!), - ]) } extension SceneController: UIWindowSceneDelegate { @@ -38,8 +22,8 @@ extension SceneController: UIWindowSceneDelegate { guard let windowScene = scene as? UIWindowScene else { return } window = UIWindow(windowScene: windowScene) + window?.rootViewController = navigator.rootViewController window?.makeKeyAndVisible() - configureRootViewController() navigator.route(rootURL) } From 05373db52766e890b5b12669153c1994af850b9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=A0vara?= Date: Fri, 6 Dec 2024 18:42:28 +0100 Subject: [PATCH 5/5] Set session's path config from the global path config. --- Source/Turbo/Navigator/Navigator.swift | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Source/Turbo/Navigator/Navigator.swift b/Source/Turbo/Navigator/Navigator.swift index 29fd1ea..13c5c47 100644 --- a/Source/Turbo/Navigator/Navigator.swift +++ b/Source/Turbo/Navigator/Navigator.swift @@ -33,14 +33,13 @@ public class Navigator { /// Convenience initializer that doesn't require manually creating `Session` instances. /// - Parameters: - /// - pathConfiguration: _optional:_ remote configuration reference /// - delegate: _optional:_ delegate to handle custom view controllers - public convenience init(pathConfiguration: PathConfiguration? = nil, delegate: NavigatorDelegate? = nil) { + public convenience init(delegate: NavigatorDelegate? = nil) { let session = Session(webView: Hotwire.config.makeWebView()) - session.pathConfiguration = pathConfiguration + session.pathConfiguration = Hotwire.config.pathConfiguration let modalSession = Session(webView: Hotwire.config.makeWebView()) - modalSession.pathConfiguration = pathConfiguration + modalSession.pathConfiguration = Hotwire.config.pathConfiguration self.init(session: session, modalSession: modalSession, delegate: delegate) }