Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to integrate Strada? #71

Closed
sevos opened this issue Oct 31, 2023 · 5 comments
Closed

How to integrate Strada? #71

sevos opened this issue Oct 31, 2023 · 5 comments

Comments

@sevos
Copy link

sevos commented Oct 31, 2023

I am struggling integrating TurboNavigator with Strada.

Strada quick start advises to implement such version of VisitableViewController:

class TurboWebViewController: VisitableViewController, BridgeDestination {

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

    // MARK: View lifecycle

    override func viewDidLoad() {
        super.viewDidLoad()
        bridgeDelegate.onViewDidLoad()
    }

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

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

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

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

    // MARK: Visitable

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

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

I figured out the private method TurboNavigator#controller (sorry for ruby'ish method digests!) is responsible for the instantiation of VisitableViewController. I've tried to extend TurboNavigator or inherit from it, but the current visibility modifiers forbits such attempts.

extension TurboNavigator {
    private func controller(for proposal: VisitProposal) -> UIViewController? {
        switch delegate.handle(proposal: proposal) {
        case .accept:
            return VisitableViewController(url: proposal.url)
        case .acceptCustom(let customViewController):
            return customViewController
        case .reject:
            return nil
        }
    }
}

The code above complains that delegate is private.

How would you approach this?

@joemasilotti
Copy link
Owner

This part of the README should guide you in the right direction. https://github.com/joemasilotti/TurboNavigator

  1. Set the delegate of Turbo Navigator
  2. Implement the function to return your controller

@marcoroth
Copy link

It's probably also worth to mention here: https://masilotti.com/strada-and-turbo-navigator/

@joemasilotti
Copy link
Owner

Thanks @marcoroth! This issue prompted that post and I totally forgot to link to it.

@sevos, have you gotten it to work?

@sevos
Copy link
Author

sevos commented Nov 3, 2023

Hey @joemasilotti - Thank you so much! It works! :)

One thing that might be worth adjusting in the article would be to include "Turbo Native" string in the user agent:

        TurboConfig.shared.userAgent += "Turbo Native \(Strada.userAgentSubstring(for: BridgeComponent.allTypes))"

It's common to use turbo_native_app? helper in Rails and it reacts to this substring

EDIT: I see, you are just appending there, got confused, sorry!

@joemasilotti
Copy link
Owner

Awesome, glad it was helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants