From 936f5c9dea0b30215d80a4a1048a7ed74e5e2409 Mon Sep 17 00:00:00 2001 From: Mikhail Maslo Date: Thu, 13 Jul 2023 19:21:37 +0200 Subject: [PATCH 1/3] Add convenience to navigation controller. Add new parameters to the demo --- .../Screens/Root/RootViewController.swift | 9 ++++++++- .../Extensions/UIViewController+Convenience.swift | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/BottomSheetDemo/Sources/User Interface/Screens/Root/RootViewController.swift b/BottomSheetDemo/Sources/User Interface/Screens/Root/RootViewController.swift index 67317f2..42be8b5 100644 --- a/BottomSheetDemo/Sources/User Interface/Screens/Root/RootViewController.swift +++ b/BottomSheetDemo/Sources/User Interface/Screens/Root/RootViewController.swift @@ -54,7 +54,14 @@ final class RootViewController: UIViewController { let viewController = ResizeViewController(initialHeight: 300) presentBottomSheetInsideNavigationController( viewController: viewController, - configuration: .default + configuration: .default, + canBeDismissed: { + // return true / false based on your business logic + true + }, + dismissCompletion: { + // react on dismiss completion + } ) } } diff --git a/Sources/BottomSheet/Core/Extensions/UIViewController+Convenience.swift b/Sources/BottomSheet/Core/Extensions/UIViewController+Convenience.swift index 2e69656..60ec5cf 100644 --- a/Sources/BottomSheet/Core/Extensions/UIViewController+Convenience.swift +++ b/Sources/BottomSheet/Core/Extensions/UIViewController+Convenience.swift @@ -106,8 +106,18 @@ public extension UIViewController { present(viewController, animated: true, completion: nil) } - func presentBottomSheetInsideNavigationController(viewController: UIViewController, configuration: BottomSheetConfiguration) { + func presentBottomSheetInsideNavigationController( + viewController: UIViewController, + configuration: BottomSheetConfiguration, + canBeDismissed: @escaping (() -> Bool) = { true }, + dismissCompletion: (() -> Void)? = nil + ) { let navigationController = BottomSheetNavigationController(rootViewController: viewController, configuration: configuration) - presentBottomSheet(viewController: navigationController, configuration: configuration) + presentBottomSheet( + viewController: navigationController, + configuration: configuration, + canBeDismissed: canBeDismissed, + dismissCompletion: dismissCompletion + ) } } From 16380a793cdc3c273036a3e1020bf9729cfc977d Mon Sep 17 00:00:00 2001 From: Mikhail Maslo Date: Thu, 13 Jul 2023 19:31:38 +0200 Subject: [PATCH 2/3] Add docs for new customizations --- .../User Interface/Screens/Root/RootViewController.swift | 4 ++-- README.md | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/BottomSheetDemo/Sources/User Interface/Screens/Root/RootViewController.swift b/BottomSheetDemo/Sources/User Interface/Screens/Root/RootViewController.swift index 42be8b5..678daee 100644 --- a/BottomSheetDemo/Sources/User Interface/Screens/Root/RootViewController.swift +++ b/BottomSheetDemo/Sources/User Interface/Screens/Root/RootViewController.swift @@ -56,11 +56,11 @@ final class RootViewController: UIViewController { viewController: viewController, configuration: .default, canBeDismissed: { - // return true / false based on your business logic + // return `true` or `false` based on your business logic true }, dismissCompletion: { - // react on dismiss completion + // handle dismiss completion if user closed bottom sheet by a gesture } ) } diff --git a/README.md b/README.md index 4266afc..86f4c95 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,14 @@ presentBottomSheet( cornerRadius: 10, pullBarConfiguration: .visible(.init(height: 20)), shadowConfiguration: .init(backgroundColor: UIColor.black.withAlphaComponent(0.6)) - ) + ), + canBeDismissed: { + // return `true` or `false` based on your business logic + true + }, + dismissCompletion: { + // handle dismiss completion if user closed bottom sheet by a gesture + } ) ``` From 0c117417c0cdcee6384cac6949b44ea3c11ebd7d Mon Sep 17 00:00:00 2001 From: Mikhail Maslo Date: Thu, 13 Jul 2023 19:35:51 +0200 Subject: [PATCH 3/3] Invoke `dismissCompletion` when user dismissed bottom sheet by interactive gesture --- .../Core/Extensions/UIViewController+Convenience.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/BottomSheet/Core/Extensions/UIViewController+Convenience.swift b/Sources/BottomSheet/Core/Extensions/UIViewController+Convenience.swift index 60ec5cf..a0015bf 100644 --- a/Sources/BottomSheet/Core/Extensions/UIViewController+Convenience.swift +++ b/Sources/BottomSheet/Core/Extensions/UIViewController+Convenience.swift @@ -69,7 +69,12 @@ public final class DefaultBottomSheetModalDismissalHandler: BottomSheetModalDism } public func performDismissal(animated: Bool) { - presentingViewController?.presentedViewController?.dismiss(animated: animated, completion: dismissCompletion) + if let presentedViewController = presentingViewController { + presentedViewController.dismiss(animated: animated, completion: dismissCompletion) + } else { + // User dismissed view controller by swipe-gesture, dismiss handler wasn't invoked + dismissCompletion?() + } } }