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

Fix not working web view navigation regression issue #77

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
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
14 changes: 10 additions & 4 deletions catowseriOS/catowser/Coordinators/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,16 @@ private extension AppCoordinator {
plugins,
uiFramework)
coordinator.parent = self
coordinator.start()
// Set new interface after starting, it is new for every site/webView
siteNavigator = coordinator.startedVC as? WebViewNavigatable
webContentCoordinator = coordinator
let context: WebViewContextImpl = .init(plugins)
Task {
/// Need to do init of view model from outside, because `start` needs to be synhronious to be able to get non nil `startedVC`
let viewModel = await ViewModelFactory.shared.getWebViewModel(site, context, coordinator)
coordinator.viewModel = viewModel
coordinator.start()
// Set new interface after starting, it is new for every site/webView
siteNavigator = coordinator.startedVC as? WebViewNavigatable
webContentCoordinator = coordinator
}
case .swiftUIWrapper, .swiftUI:
break
}
Expand Down
37 changes: 19 additions & 18 deletions catowseriOS/catowser/Coordinators/WebContentCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ final class WebContentCoordinator: Coordinator {
private var sitePresenter: WebViewNavigatable?
/// Mode is needed only to determine if web view model needs to call the load method or not (SwiftUI mode need to not call it)
private let mode: UIFrameworkType
/// View model should be not private to be able to set it later, because it has async init
var viewModel: (any WebViewModel)?

init(_ vcFactory: ViewControllerFactory,
_ presenter: AnyViewController,
Expand All @@ -60,25 +62,24 @@ final class WebContentCoordinator: Coordinator {
}

func start() {
Task {
let context: WebViewContextImpl = .init(jsPluginsSource)
let viewModel = await ViewModelFactory.shared.getWebViewModel(site, context, self)
let manager = ViewsEnvironment.shared.reuseManager
let webViewController = try? manager.controllerFor(site, self, viewModel, mode)
guard let vc = webViewController else {
assertionFailure("Failed create new web view for tab")
return
}
startedVC = vc
sitePresenter = vc
presenterVC?.viewController.add(asChildViewController: vc.viewController, to: contentContainerView)
let topSitesView: UIView = vc.controllerView
topSitesView.translatesAutoresizingMaskIntoConstraints = false
topSitesView.leadingAnchor.constraint(equalTo: contentContainerView.leadingAnchor).isActive = true
topSitesView.trailingAnchor.constraint(equalTo: contentContainerView.trailingAnchor).isActive = true
topSitesView.topAnchor.constraint(equalTo: contentContainerView.topAnchor).isActive = true
topSitesView.bottomAnchor.constraint(equalTo: contentContainerView.bottomAnchor).isActive = true
let manager = ViewsEnvironment.shared.reuseManager
guard let viewModel else {
return
}
let webViewController = try? manager.controllerFor(site, self, viewModel, mode)
guard let vc = webViewController else {
assertionFailure("Failed create new web view for tab")
return
}
startedVC = vc
sitePresenter = vc
presenterVC?.viewController.add(asChildViewController: vc.viewController, to: contentContainerView)
let topSitesView: UIView = vc.controllerView
topSitesView.translatesAutoresizingMaskIntoConstraints = false
topSitesView.leadingAnchor.constraint(equalTo: contentContainerView.leadingAnchor).isActive = true
topSitesView.trailingAnchor.constraint(equalTo: contentContainerView.trailingAnchor).isActive = true
topSitesView.topAnchor.constraint(equalTo: contentContainerView.topAnchor).isActive = true
topSitesView.bottomAnchor.constraint(equalTo: contentContainerView.bottomAnchor).isActive = true
}
}

Expand Down
Loading