Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional modal presentation styles #61

Merged
merged 7 commits into from
Dec 17, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ extension UINavigationController {
modalPresentationStyle = .automatic
case .full:
modalPresentationStyle = .fullScreen
case .pageSheet:
modalPresentationStyle = .pageSheet
case .formSheet:
modalPresentationStyle = .formSheet
}
}
}
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.modalSheetDismissGestureEnabled
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ public extension VisitProposal {
properties["pull_to_refresh_enabled"] as? Bool ?? true
}

var modalSheetDismissGestureEnabled: Bool {
if let dismissEnabled = properties["modal_sheet_dismiss_gesture_enabled"] as? Bool {
jayohms marked this conversation as resolved.
Show resolved Hide resolved
return dismissEnabled
}

return 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:
Expand Down
2 changes: 2 additions & 0 deletions Source/Turbo/Navigator/Helpers/Navigation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ public enum Navigation {
case medium
case large
case full
case pageSheet
case formSheet
Comment on lines +21 to +22
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate to come in late after a merge, but I think these should be:

case pageSheet = "page_sheet"
case formSheet = "form_sheet"

to match Navigation.Presentation.clearAll and Navigation.Presentation.replaceRoot.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in PR #63.

}
}
4 changes: 4 additions & 0 deletions Source/Turbo/Navigator/NavigationHierarchyController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class NavigationHierarchyController {
if let visitable = controller as? Visitable {
delegate.visit(visitable, on: .modal, with: proposal.options)
}
controller.configureModalBehaviour(with: proposal)

if navigationController.presentedViewController != nil, !modalNavigationController.isBeingDismissed {
pushOrReplace(on: modalNavigationController, with: controller, via: proposal)
} else {
Expand Down Expand Up @@ -160,6 +162,8 @@ class NavigationHierarchyController {
if let visitable = controller as? Visitable {
delegate.visit(visitable, on: .modal, with: proposal.options)
}
controller.configureModalBehaviour(with: proposal)

if navigationController.presentedViewController != nil {
modalNavigationController.replaceLastViewController(with: controller)
} else {
Expand Down