-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from hotwired/additional-modal-presentation-st…
…yles Additional modal presentation styles
- Loading branch information
Showing
9 changed files
with
279 additions
and
52 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
Source/Turbo/Navigator/Extensions/PathPropertiesExtensions.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,75 @@ | ||
public extension PathProperties { | ||
var context: Navigation.Context { | ||
guard let rawValue = self["context"] as? String, | ||
let context = Navigation.Context(rawValue: rawValue) else { | ||
return .default | ||
} | ||
|
||
return context | ||
} | ||
|
||
var presentation: Navigation.Presentation { | ||
guard let rawValue = self["presentation"] as? String, | ||
let presentation = Navigation.Presentation(rawValue: rawValue) else { | ||
return .default | ||
} | ||
|
||
return presentation | ||
} | ||
|
||
var modalStyle: Navigation.ModalStyle { | ||
guard let rawValue = self["modal_style"] as? String, | ||
let modalStyle = Navigation.ModalStyle(rawValue: rawValue) else { | ||
return .large | ||
} | ||
|
||
return modalStyle | ||
} | ||
|
||
var pullToRefreshEnabled: Bool { | ||
self["pull_to_refresh_enabled"] as? Bool ?? true | ||
} | ||
|
||
var modalDismissGestureEnabled: Bool { | ||
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. | ||
/// | ||
/// For example, given the following configuration file: | ||
/// | ||
/// ```json | ||
/// { | ||
/// "rules": [ | ||
/// { | ||
/// "patterns": [ | ||
/// "/recipes/*" | ||
/// ], | ||
/// "properties": { | ||
/// "view_controller": "recipes", | ||
/// } | ||
/// } | ||
/// ] | ||
/// } | ||
/// ``` | ||
/// | ||
/// A VisitProposal to `https://example.com/recipes/` will have | ||
/// ```swift | ||
/// proposal.viewController == "recipes" | ||
/// ``` | ||
/// | ||
/// - 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 { | ||
guard let viewController = self["view_controller"] as? String else { | ||
return VisitableViewController.pathConfigurationIdentifier | ||
} | ||
|
||
return viewController | ||
} | ||
|
||
/// Allows the proposal to change the animation status when pushing, popping or presenting. | ||
var animated: Bool { | ||
self["animated"] as? Bool ?? true | ||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
Source/Turbo/Navigator/Extensions/UIViewController+ModalBehaviour.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,7 @@ | ||
import UIKit | ||
|
||
extension UIViewController { | ||
func configureModalBehaviour(with proposal: VisitProposal) { | ||
isModalInPresentation = !proposal.modalDismissGestureEnabled | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,5 +18,7 @@ public enum Navigation { | |
case medium | ||
case large | ||
case full | ||
case pageSheet | ||
case formSheet | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"rules":[ | ||
{ | ||
"patterns":[ | ||
"/new$" | ||
], | ||
"properties":{ | ||
"context":"modal", | ||
"modal_dismiss_gesture_enabled": false | ||
} | ||
}, | ||
{ | ||
"patterns":[ | ||
"/newMedium$" | ||
], | ||
"properties":{ | ||
"context":"modal", | ||
"modal_style":"medium", | ||
"modal_dismiss_gesture_enabled": true | ||
} | ||
}, | ||
{ | ||
"patterns":[ | ||
"/newLarge$" | ||
], | ||
"properties":{ | ||
"background_color":"black", | ||
"context":"modal", | ||
"modal_style":"large" | ||
} | ||
}, | ||
{ | ||
"patterns":[ | ||
"/newFull$" | ||
], | ||
"properties":{ | ||
"context":"modal", | ||
"modal_style":"full" | ||
} | ||
}, | ||
{ | ||
"patterns":[ | ||
"/newPageSheet$" | ||
], | ||
"properties":{ | ||
"context":"modal", | ||
"modal_style":"pageSheet" | ||
} | ||
}, | ||
{ | ||
"patterns":[ | ||
"/newFormSheet$" | ||
], | ||
"properties":{ | ||
"context":"modal", | ||
"modal_style":"formSheet" | ||
} | ||
} | ||
] | ||
} |
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.