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

Fernando/turbo navigator feedback #163

Merged
merged 3 commits into from
Nov 20, 2023
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
5 changes: 4 additions & 1 deletion Demo/NumbersViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import UIKit

/// A simple native table view controller to demonstrate loading non-Turbo screens
/// for a visit proposal
final class NumbersViewController: UITableViewController {
final class NumbersViewController: UITableViewController, PathConfigurationIdentifiable {

static var pathConfigurationIdentifier: String { "numbers" }

convenience init(url: URL, navigator: Navigator) {
self.init(nibName: nil, bundle: nil)
self.url = url
Expand Down
5 changes: 4 additions & 1 deletion Demo/SceneController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,15 @@ extension SceneController: UIWindowSceneDelegate {
extension SceneController: TurboNavigatorDelegate {
func handle(proposal: VisitProposal) -> ProposalResult {
switch proposal.viewController {
case "numbers":

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a style guide we can follow for Swift code? I feel like we've gone back and forth removing/adding these blank lines a few times!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆

We don't use a style guide, but if you don't like the new lines, I'll adapt. I don't feel strongly about it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I just run SwiftFormat on every file before I save it!

case NumbersViewController.pathConfigurationIdentifier:
return .acceptCustom(NumbersViewController(url: proposal.url, navigator: navigator))

case "numbersDetail":
let alertController = UIAlertController(title: "Number", message: "\(proposal.url.lastPathComponent)", preferredStyle: .alert)
alertController.addAction(.init(title: "OK", style: .default, handler: nil))
return .acceptCustom(alertController)

default:
return .acceptCustom(TurboWebViewController(url: proposal.url))
}
Expand Down
10 changes: 6 additions & 4 deletions Source/Turbo Navigator/Extensions/VisitProposalExtension.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
public extension VisitProposal {
var context: Navigation.Context {
var context: TurboNavigation.Context {
if let rawValue = properties["context"] as? String {
return Navigation.Context(rawValue: rawValue) ?? .default
return TurboNavigation.Context(rawValue: rawValue) ?? .default
}
return .default
}

var presentation: Navigation.Presentation {
var presentation: TurboNavigation.Presentation {
if let rawValue = properties["presentation"] as? String {
return Navigation.Presentation(rawValue: rawValue) ?? .default
return TurboNavigation.Presentation(rawValue: rawValue) ?? .default
}
return .default
}
Expand All @@ -35,6 +35,8 @@ public extension VisitProposal {
/// A VisitProposal to `https://example.com/recipes/` will have `proposal.viewController == "recipes"`
///
/// A default value is provided in case the view controller property is missing from the configuration file. This will route the default `VisitableViewController`.
///
/// For convenience, conform `ViewController`s to `PathConfigurationIdentifiable` to couple the identifier with a view controller.
var viewController: String {
if let viewController = properties["view-controller"] as? String {
return viewController
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public enum Navigation {
public enum TurboNavigation {
public enum Context: String {
case `default`
case modal
Expand Down
2 changes: 1 addition & 1 deletion Tests/Turbo Navigator/TurboNavigatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ private class EmptyNavigationDelegate: TurboNavigationHierarchyControllerDelegat
// MARK: - VisitProposal extension

private extension VisitProposal {
init(path: String = "", action: VisitAction = .advance, context: Navigation.Context = .default, presentation: Navigation.Presentation = .default) {
init(path: String = "", action: VisitAction = .advance, context: TurboNavigation.Context = .default, presentation: TurboNavigation.Presentation = .default) {
let url = URL(string: "https://example.com")!.appendingPathComponent(path)
let options = VisitOptions(action: action, response: nil)
let properties: PathProperties = [
Expand Down