Skip to content

Commit

Permalink
Group functions in TurboNavigator by access modifiers.
Browse files Browse the repository at this point in the history
  • Loading branch information
svara committed Mar 5, 2024
1 parent f8c4678 commit f6e0be6
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions Source/Turbo Navigator/TurboNavigator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,6 @@ public class TurboNavigator {
}
}

/// Internal initializer requiring preconfigured `Session` instances.
///
/// User `init(pathConfiguration:delegate:)` to only provide a `PathConfiguration`.
/// - Parameters:
/// - session: the main `Session`
/// - modalSession: the `Session` used for the modal navigation controller
/// - delegate: _optional:_ delegate to handle custom view controllers
init(session: Session, modalSession: Session, delegate: TurboNavigatorDelegate? = nil) {
self.session = session
self.modalSession = modalSession

self.delegate = delegate ?? navigatorDelegate

self.session.delegate = self
self.modalSession.delegate = self

self.webkitUIDelegate = TurboWKUIController(delegate: self)
session.webView.uiDelegate = webkitUIDelegate
modalSession.webView.uiDelegate = webkitUIDelegate
}

/// Convenience initializer that doesn't require manually creating `Session` instances.
/// - Parameters:
/// - pathConfiguration: _optional:_ remote configuration reference
Expand Down Expand Up @@ -108,23 +87,48 @@ public class TurboNavigator {

public func appDidBecomeActive() {
appInBackground = false
inspectAllSession()
inspectAllSessions()
}

public func appDidEnterBackground() {
appInBackground = true
}


// MARK: Internal

var session: Session
var modalSession: Session

/// Modifies a UINavigationController according to visit proposals.
lazy var hierarchyController = TurboNavigationHierarchyController(delegate: self)

/// Internal initializer requiring preconfigured `Session` instances.
///
/// User `init(pathConfiguration:delegate:)` to only provide a `PathConfiguration`.
/// - Parameters:
/// - session: the main `Session`
/// - modalSession: the `Session` used for the modal navigation controller
/// - delegate: _optional:_ delegate to handle custom view controllers
init(session: Session, modalSession: Session, delegate: TurboNavigatorDelegate? = nil) {
self.session = session
self.modalSession = modalSession

self.delegate = delegate ?? navigatorDelegate

self.session.delegate = self
self.modalSession.delegate = self

self.webkitUIDelegate = TurboWKUIController(delegate: self)
session.webView.uiDelegate = webkitUIDelegate
modalSession.webView.uiDelegate = webkitUIDelegate
}

// MARK: Private

/// A default delegate implementation if none is provided.
private let navigatorDelegate = DefaultTurboNavigatorDelegate()
private var backgroundTerminatedWebViewSessions = [Session]()
private var appInBackground = false

private func controller(for proposal: VisitProposal) -> UIViewController? {
switch delegate.handle(proposal: proposal) {
case .accept:
Expand Down Expand Up @@ -219,7 +223,7 @@ extension TurboNavigator: TurboWKUIDelegate {
// MARK: - Session and web view reloading

extension TurboNavigator {
private func inspectAllSession() {
private func inspectAllSessions() {
[session, modalSession].forEach { inspect($0) }
}

Expand Down

0 comments on commit f6e0be6

Please sign in to comment.