Skip to content
This repository was archived by the owner on Jul 6, 2022. It is now read-only.
Open
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
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
matrix:
destination:
- generic/platform=iOS
- generic/platform=macOS

steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import PackageDescription
let package = Package(
name: "Router",
platforms: [
.iOS(.v11)
.iOS(.v11),
.macOS(.v10_15)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
Expand Down
25 changes: 25 additions & 0 deletions Sources/Router/Router/Environment+router.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
import SwiftUI

@available(iOS 13, macOS 10.15, *)
struct WeakRouter<R: Router & AnyObject>: Router {
weak var _router: R?

func navigate<Target, ThePresenter>(to target: Target, _ environmentObject: Target.EnvironmentObjectDependency, using presenter: ThePresenter, source: RouteViewIdentifier?) -> RouteViewIdentifier where Target : EnvironmentDependentRoute, ThePresenter : Presenter {
_router?.navigate(to: target, environmentObject, using: presenter, source: source) ?? .init()
}

func replaceRoot<Target, ThePresenter>(with target: Target, _ environmentObject: Target.EnvironmentObjectDependency, using presenter: ThePresenter) -> RouteViewIdentifier where Target : EnvironmentDependentRoute, ThePresenter : Presenter {
_router?.replaceRoot(with: target, environmentObject, using: presenter) ?? .init()
}

func dismissUpTo(routeMatchingId id: RouteViewIdentifier) {
_router?.dismissUpTo(routeMatchingId: id)
}

func dismissUpToIncluding(routeMatchingId id: RouteViewIdentifier) {
_router?.dismissUpToIncluding(routeMatchingId: id)
}

func isPresenting(routeMatchingId id: RouteViewIdentifier) -> Bool {
_router?.isPresenting(routeMatchingId: id) ?? false
}
}

@available(iOS 13, macOS 10.15, *)
fileprivate struct RouterKey: EnvironmentKey {
typealias Value = Router?
Expand Down
Loading