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

server driven navigation without path configuration #74

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
31 changes: 31 additions & 0 deletions Source/Turbo/Navigator/NavigationHierarchyController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,32 @@ import SafariServices
import UIKit
import WebKit

extension NavigationHierarchyController {
/// Handles special Turbo historical location routes
private func handleHistoricalLocation(proposal: VisitProposal) {
switch proposal.url.path {
case "/recede_historical_location":
// Pop or dismiss the current view
pop(animated: proposal.animated)

case "/resume_historical_location":
// No-op - do nothing
break

case "/refresh_historical_location":
// refresh current view
refresh(via: proposal)
default:
break
}
}

/// Check if URL is a Turbo historical location directive
private func isHistoricalLocation(_ url: URL) -> Bool {
return url.path.hasSuffix("_historical_location")
}
}

class NavigationHierarchyController {
let navigationController: UINavigationController
let modalNavigationController: UINavigationController
Expand Down Expand Up @@ -34,6 +60,11 @@ class NavigationHierarchyController {
}

func route(controller: UIViewController, proposal: VisitProposal) {
if isHistoricalLocation(proposal.url) {
handleHistoricalLocation(proposal: proposal)
return
}

if let alert = controller as? UIAlertController {
presentAlert(alert, via: proposal)
} else {
Expand Down