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

Pages are reloaded when switching between tabs #40

Open
joemasilotti opened this issue Oct 18, 2024 · 1 comment
Open

Pages are reloaded when switching between tabs #40

joemasilotti opened this issue Oct 18, 2024 · 1 comment

Comments

@joemasilotti
Copy link
Member

When switching between tabs a web view is always reloaded via a .restore visit.

Session line 260, introduced in turbo-ios PR #189, assumes a single navigation controller which then triggers the restoration visit. This occurs from HotwireWebViewController.viewWillAppear(_:) being called before the web view appears when switching between tabs.

Demo.mov

Replace "switching tabs" with any native to web interaction - I'm only using tabs here because that's where I noticed the issue. But this would also occur if you had a split view controller or similar - anytime viewWillAppear(_:) would be called on the view controller.

To reproduce

  1. Create a new Xcode project
  2. Add the Hotwire Native iOS dependency
  3. Replace SceneDelegate.swift with code below
  4. Set a breakpoint on Session line 260
  5. Switch to the native tab then back to the web tab
  6. Observe that the break point is hit and the page is reloaded
import HotwireNative
import UIKit

let baseURL = URL(string: "https://hotwire-native-demo.dev")!

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    var window: UIWindow?

    private let navigator = Navigator()

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        let tabBarController = UITabBarController()
        let secondViewController = SecondViewController()
        secondViewController.title = "Second"

        tabBarController.viewControllers = [
            navigator.rootViewController,
            secondViewController
        ]
        window?.rootViewController = tabBarController

        navigator.route(baseURL)
    }
}

class SecondViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .systemGreen
    }
}
@karlentwistle
Copy link

karlentwistle commented Oct 18, 2024

Thanks for posting this @joemasilotti. I recently upgraded the Turbo Native app at my company from turbo-ios to hotwire-native-ios, which also uses tabs, and I'm encountering this exact issue.

Ideally, we'd like users to switch between tabs without changing the state when revisiting a tab for a more seamless experience in our app.

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

No branches or pull requests

2 participants