Skip to content

Commit

Permalink
Minor cleanup / documentation improvement for release.
Browse files Browse the repository at this point in the history
  • Loading branch information
frzi committed Dec 5, 2021
1 parent 5e69c68 commit b7600df
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Sources/Navigator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import SwiftUI

/// EnvironmentObject storing the state of a Router.
///
/// Use this object to programmatically navigate to a new path, jump forward or back in the history, to clear the
/// Use this object to programmatically navigate to a new path, to jump forward or back in the history, to clear the
/// history, or to find out whether the user can go back or forward.
///
/// - Note: This EnvironmentObject is available in all children of a `Router`.
/// - Note: This EnvironmentObject is available inside the hierarchy of a `Router`.
///
/// ```swift
/// @EnvironmentObject var navigator: Navigator
Expand Down
16 changes: 7 additions & 9 deletions Sources/Route.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,13 @@ public struct Route<ValidatedData, Content: View>: View {
}

public var body: some View {
let resolvedGlob = resolvePaths(relativePath, path)

var validatedData: ValidatedData?
var routeInformation: RouteInformation?

if !switchEnvironment.isActive || (switchEnvironment.isActive && !switchEnvironment.isResolved) {
do {
if let matchInformation = try pathMatcher.match(
glob: resolvedGlob,
glob: path,
with: navigator.path,
relative: relativePath),
let validated = validator(matchInformation)
Expand Down Expand Up @@ -190,8 +188,8 @@ public extension Route where ValidatedData == RouteInformation {
/// This object contains the resolved parameters (variables) of the `Route`'s path, as well as the relative path
/// for all views inside the hierarchy.
public final class RouteInformation: ObservableObject {
/// The resolved path component of the parent `Route`.
public let matchedPath: String
/// The resolved path component of the parent `Route`. For internal use only, at the moment.
let matchedPath: String

/// The current relative path.
public let path: String
Expand Down Expand Up @@ -282,7 +280,8 @@ final class PathMatcher: ObservableObject {
}

func match(glob: String, with path: String, relative: String = "/") throws -> RouteInformation? {
let compiled = try compileRegex(glob)
let completeGlob = resolvePaths(relative, glob)
let compiled = try compileRegex(completeGlob)

var nsrange = NSRange(path.startIndex..<path.endIndex, in: path)
let matches = compiled.matchRegex.matches(in: path, options: [], range: nsrange)
Expand All @@ -309,14 +308,13 @@ final class PathMatcher: ObservableObject {
// we only want "/news/article".
nsrange = matches[0].range(at: 1) // Should be the entire capture group.
guard nsrange.location != NSNotFound,
let range = Range(nsrange, in: path) else {
let range = Range(nsrange, in: path)
else {
return nil
}

let resolvedGlob = String(path[range])
let matchedPath = String(path[relative.endIndex...])

print("resolved: \(resolvedGlob), matched: \(matchedPath), relative: \(relative)")

return RouteInformation(path: resolvedGlob, matchedPath: matchedPath, parameters: parameterValues)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftUIRouter.docc/SwiftUIRouter.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# ``SwiftUIRouter``

Easy and maintainable app navigation with path based routing for SwiftUI.
Easy and maintainable app navigation with path-based routing for SwiftUI.

![SwiftUI Router logo](logo)

With **SwiftUI Router** you can power your SwiftUI app with path based routing. By utilizing a path based system, navigation in your app becomes more flexible and easier to maintain.
With **SwiftUI Router** you can power your SwiftUI app with path-based routing. By utilizing a path-based system, navigation in your app becomes more flexible and easier to maintain.

### Additional content
- Examples can be found on [Github](https://github.com/frzi/SwiftUIRouter-Examples)
Expand Down

0 comments on commit b7600df

Please sign in to comment.