Skip to content

Commit

Permalink
Cleanup and consolidate code style in PathProperties extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
svara committed Dec 17, 2024
1 parent e38cf8b commit 2d3ca34
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions Source/Turbo/Navigator/Extensions/PathPropertiesExtensions.swift
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
public extension PathProperties {
var context: Navigation.Context {
if let rawValue = self["context"] as? String {
return Navigation.Context(rawValue: rawValue) ?? .default
guard let rawValue = self["context"] as? String,
let context = Navigation.Context(rawValue: rawValue) else {
return .default
}
return .default

return context
}

var presentation: Navigation.Presentation {
if let rawValue = self["presentation"] as? String {
return Navigation.Presentation(rawValue: rawValue) ?? .default
guard let rawValue = self["presentation"] as? String,
let presentation = Navigation.Presentation(rawValue: rawValue) else {
return .default
}
return .default

return presentation
}

var modalStyle: Navigation.ModalStyle {
if let rawValue = self["modal_style"] as? String {
return Navigation.ModalStyle(rawValue: rawValue) ?? .large
guard let rawValue = self["modal_style"] as? String,
let modalStyle = Navigation.ModalStyle(rawValue: rawValue) else {
return .large
}
return .large

return modalStyle
}

var pullToRefreshEnabled: Bool {
self["pull_to_refresh_enabled"] as? Bool ?? true
}

var modalDismissGestureEnabled: Bool {
if let dismissEnabled = self["modal_dismiss_gesture_enabled"] as? Bool {
return dismissEnabled
}

return true
self["modal_dismiss_gesture_enabled"] as? Bool ?? true
}

/// Used to identify a custom native view controller if provided in the path configuration properties of a given pattern.
Expand Down Expand Up @@ -59,19 +61,15 @@ public extension PathProperties {
/// - Important: A default value is provided in case the view controller property is missing from the configuration file. This will route the default `VisitableViewController`.
/// - Note: A `ViewController` must conform to `PathConfigurationIdentifiable` to couple the identifier with a view controlelr.
var viewController: String {
if let viewController = self["view_controller"] as? String {
return viewController
guard let viewController = self["view_controller"] as? String else {
return VisitableViewController.pathConfigurationIdentifier
}

return VisitableViewController.pathConfigurationIdentifier
return viewController
}

/// Allows the proposal to change the animation status when pushing, popping or presenting.
var animated: Bool {
if let animated = self["animated"] as? Bool {
return animated
}

return true
self["animated"] as? Bool ?? true
}
}

0 comments on commit 2d3ca34

Please sign in to comment.