Skip to content

Commit

Permalink
Move bridge delegate initialization to TurboWebViewController .
Browse files Browse the repository at this point in the history
  • Loading branch information
svara committed Sep 15, 2023
1 parent 8b559f7 commit eb88747
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
8 changes: 0 additions & 8 deletions Demo/Navigation/TurboNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,6 @@ extension TurboNavigationController {

private func visit(viewController: UIViewController, with options: VisitOptions, modal: Bool = false) {
guard let visitable = viewController as? Visitable else { return }

if let bridgeDestination = viewController as? TurboWebViewController & BridgeDestination {
let bridgeDelegate = BridgeDelegate(location: visitable.visitableURL.absoluteString,
destination: bridgeDestination,
componentTypes: BridgeComponent.allTypes)
bridgeDestination.bridgeDelegate = bridgeDelegate
}

// Each Session corresponds to a single web view. A good rule of thumb
// is to use a session per navigation stack. Here we're using a different session
// when presenting a modal. We keep that around for any modal presentations so
Expand Down
27 changes: 16 additions & 11 deletions Demo/TurboWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,57 @@ import Strada
import WebKit

final class TurboWebViewController: VisitableViewController,
ErrorPresenter,
BridgeDestination {
var bridgeDelegate: BridgeDelegate?
ErrorPresenter,
BridgeDestination {

private lazy var bridgeDelegate: BridgeDelegate = {
BridgeDelegate(location: visitableURL.absoluteString,
destination: self,
componentTypes: BridgeComponent.allTypes)
}()

// MARK: View lifecycle

override func viewDidLoad() {
super.viewDidLoad()

navigationItem.backButtonDisplayMode = .minimal
view.backgroundColor = .systemBackground

if presentingViewController != nil {
navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(dismissModal))
}
bridgeDelegate?.onViewDidLoad()
bridgeDelegate.onViewDidLoad()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
bridgeDelegate?.onViewWillAppear()
bridgeDelegate.onViewWillAppear()
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
bridgeDelegate?.onViewDidAppear()
bridgeDelegate.onViewDidAppear()
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
bridgeDelegate?.onViewWillDisappear()
bridgeDelegate.onViewWillDisappear()
}

override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
bridgeDelegate?.onViewDidDisappear()
bridgeDelegate.onViewDidDisappear()
}

// MARK: Visitable

override func visitableDidActivateWebView(_ webView: WKWebView) {
bridgeDelegate?.webViewDidBecomeActive(webView)
bridgeDelegate.webViewDidBecomeActive(webView)
}

override func visitableDidDeactivateWebView() {
bridgeDelegate?.webViewDidBecomeDeactivated()
bridgeDelegate.webViewDidBecomeDeactivated()
}

// MARK: Actions
Expand Down

0 comments on commit eb88747

Please sign in to comment.