Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Create sessions only when needed #70

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions Sources/TurboNavigator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,16 @@ public class TurboNavigator {
/// - pathConfiguration: assigned to internal `Session` instances for custom configuration
/// - navigationController: optional: override the main navigation stack
/// - modalNavigationController: optional: override the modal navigation stack
public init(delegate: TurboNavigationDelegate,
pathConfiguration: PathConfiguration? = nil,
navigationController: UINavigationController = UINavigationController(),
modalNavigationController: UINavigationController = UINavigationController())
public init(
delegate: TurboNavigationDelegate,
pathConfiguration: PathConfiguration? = nil,
navigationController: UINavigationController = UINavigationController(),
modalNavigationController: UINavigationController = UINavigationController())
{
self.session = Session(webView: TurboConfig.shared.makeWebView())
self.modalSession = Session(webView: TurboConfig.shared.makeWebView())
self.delegate = delegate
self.pathConfiguration = pathConfiguration
self.navigationController = navigationController
self.modalNavigationController = modalNavigationController

session.delegate = self
modalSession.delegate = self
session.pathConfiguration = pathConfiguration
modalSession.pathConfiguration = pathConfiguration
}

/// Provide `Turbo.Session` instances with preconfigured path configurations and delegates.
Expand All @@ -37,18 +32,16 @@ public class TurboNavigator {
/// - delegate: handle non-routing behavior, like custom error handling
/// - navigationController: optional: override the main navigation stack
/// - modalNavigationController: optional: override the modal navigation stack
public init(preconfiguredMainSession: Turbo.Session,
preconfiguredModalSession: Turbo.Session,
delegate: TurboNavigationDelegate,
navigationController: UINavigationController = UINavigationController(),
modalNavigationController: UINavigationController = UINavigationController())
public convenience init(
preconfiguredMainSession: Turbo.Session,
preconfiguredModalSession: Turbo.Session,
delegate: TurboNavigationDelegate,
navigationController: UINavigationController = UINavigationController(),
modalNavigationController: UINavigationController = UINavigationController())
{
self.init(delegate: delegate, navigationController: navigationController, modalNavigationController: modalNavigationController)
self.session = preconfiguredMainSession
self.modalSession = preconfiguredModalSession
self.navigationController = navigationController
self.modalNavigationController = modalNavigationController

self.delegate = delegate
}

public var rootViewController: UIViewController { navigationController }
Expand Down Expand Up @@ -89,8 +82,8 @@ public class TurboNavigator {

// MARK: Internal

let session: Session
let modalSession: Session
lazy var session = makeSession()
lazy var modalSession = makeSession()

// MARK: Private

Expand All @@ -100,6 +93,14 @@ public class TurboNavigator {
}

private unowned let delegate: TurboNavigationDelegate
private let pathConfiguration: PathConfiguration?

private func makeSession() -> Session {
let session = Session(webView: TurboConfig.shared.makeWebView())
session.delegate = self
session.pathConfiguration = pathConfiguration
return session
}

private func controller(for proposal: VisitProposal) -> UIViewController? {
switch delegate.handle(proposal: proposal) {
Expand Down
Loading