-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Reuseable Navigation Actions - changed `ParentCoordinated` to `AnyParentCoordinated` and let ParentCoordinated adapt parent as Coordinator - added basic unit tests - added reusable navigation actions to `AppStep` for taskDetail * cleanup * fix
- Loading branch information
1 parent
de736b4
commit 16e0447
Showing
19 changed files
with
346 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
SwordinatorDemo/SwordinatorDemo/Features/Helper/AppDeeplinkStep+Convert.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// AppDeeplinkStep+Convert.swift | ||
// SwordinatorDemo | ||
// | ||
// Created by Timotheus Laubengaier on 2021/10/19. | ||
// | ||
|
||
import Foundation | ||
|
||
extension AppDeeplinkStep { | ||
static func convert(url: URL) -> AppDeeplinkStep? { | ||
guard | ||
let components = NSURLComponents(url: url, resolvingAgainstBaseURL: true) | ||
else { | ||
return nil | ||
} | ||
|
||
guard | ||
let host = components.host, | ||
let path = components.path | ||
//let params = components.queryItems | ||
else { | ||
return nil | ||
} | ||
print("host = \(host)") | ||
print("path = \(path)") | ||
|
||
if host == "newTask" { | ||
return .taskDetail(task: Task(id: 10, name: "Test1")) | ||
} else if host == "tasks", let path = Int(url.pathComponents[1]) { | ||
return .taskDetailLazy(id: path) | ||
} else if host == "tasks" { | ||
return .tasks | ||
} else if host == "profile" { | ||
return .profile | ||
} else if host == "logout" { | ||
return .logout | ||
} else if host == "settings" { | ||
return .profileSettings | ||
} | ||
return nil | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
SwordinatorDemo/SwordinatorDemo/Features/Helper/NavCoordinator.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// NavCoordinator.swift | ||
// SwordinatorDemo | ||
// | ||
// Created by Timotheus Laubengaier on 2021/10/19. | ||
// | ||
|
||
import Foundation | ||
import MBProgressHUD | ||
import Swordinator | ||
|
||
protocol NavCoordinator: NavigationControllerCoordinator, ParentCoordinated, HasServices where Parent == Coordinator {} | ||
|
||
// MARK: Task Actions | ||
extension NavCoordinator { | ||
|
||
func navigateToTask(id: Int) { | ||
MBProgressHUD.showAdded(to: navigationController.view, animated: true) | ||
services.lazyTask(id: id) { task in | ||
MBProgressHUD.hide(for: self.navigationController.view, animated: true) | ||
guard let task = task else { return } | ||
self.navigateToTask(task: task) | ||
} | ||
} | ||
|
||
func navigateToTask(task: Task) { | ||
let nvc = UINavigationController() | ||
let coordinator = TaskDetailCoordinator(navigationController: nvc, services: services, task: task) | ||
coordinator.parent = self | ||
navigationController.present(nvc, animated: true, completion: nil) | ||
childCoordinators.append(coordinator) | ||
} | ||
|
||
func endNavigateToTask(animated: Bool, shouldDismiss: Bool = false, completion: (() -> Void)? = nil) { | ||
parent?.handle(step: AppStep.taskDetailCompleted) | ||
if shouldDismiss { | ||
navigationController.dismiss(animated: animated, completion: completion) | ||
} | ||
} | ||
|
||
func releaseTaskDetail() { | ||
releaseChild(type: TaskDetailCoordinator.self) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.