From 060c3f8d12ecbe7e9edcc6665ec68da1f2c7b05d Mon Sep 17 00:00:00 2001 From: Mikhail Maslo Date: Thu, 13 Jul 2023 19:07:58 +0200 Subject: [PATCH 1/2] Provide ability to control dismiss behavior. Also add `dismissCompletion` --- .../UIViewController+Convenience.swift | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Sources/BottomSheet/Core/Extensions/UIViewController+Convenience.swift b/Sources/BottomSheet/Core/Extensions/UIViewController+Convenience.swift index 990a51f..2e69656 100644 --- a/Sources/BottomSheet/Core/Extensions/UIViewController+Convenience.swift +++ b/Sources/BottomSheet/Core/Extensions/UIViewController+Convenience.swift @@ -47,21 +47,26 @@ public final class DefaultBottomSheetModalDismissalHandler: BottomSheetModalDism // MARK: - Private properties private weak var presentingViewController: UIViewController? + private let _canBeDismissed: () -> Bool private let dismissCompletion: (() -> Void)? // MARK: - Init init( presentingViewController: UIViewController?, + canBeDismissed: @escaping (() -> Bool), dismissCompletion: (() -> Void)? ) { self.presentingViewController = presentingViewController + self._canBeDismissed = canBeDismissed self.dismissCompletion = dismissCompletion } // MARK: - BottomSheetModalDismissalHandler - public let canBeDismissed = true + public var canBeDismissed: Bool { + _canBeDismissed() + } public func performDismissal(animated: Bool) { presentingViewController?.presentedViewController?.dismiss(animated: animated, completion: dismissCompletion) @@ -76,14 +81,20 @@ public extension UIViewController { private static var bottomSheetTransitionDelegateKey: UInt8 = 0 - func presentBottomSheet(viewController: UIViewController, configuration: BottomSheetConfiguration) { + func presentBottomSheet( + viewController: UIViewController, + configuration: BottomSheetConfiguration, + canBeDismissed: @escaping (() -> Bool) = { true }, + dismissCompletion: (() -> Void)? = nil + ) { weak var presentingViewController = self weak var currentBottomSheetTransitionDelegate: UIViewControllerTransitioningDelegate? let presentationControllerFactory = DefaultBottomSheetPresentationControllerFactory(configuration: configuration) { - DefaultBottomSheetModalDismissalHandler(presentingViewController: presentingViewController) { + DefaultBottomSheetModalDismissalHandler(presentingViewController: presentingViewController, canBeDismissed: canBeDismissed) { if currentBottomSheetTransitionDelegate === presentingViewController?.bottomSheetTransitionDelegate { presentingViewController?.bottomSheetTransitionDelegate = nil } + dismissCompletion?() } } bottomSheetTransitionDelegate = BottomSheetTransitioningDelegate( From cbf4aa4b2a3ea341d6dac5cb315fc4b1ee765226 Mon Sep 17 00:00:00 2001 From: Mikhail Maslo Date: Thu, 13 Jul 2023 19:07:11 +0200 Subject: [PATCH 2/2] Fix iOS 12 crash --- .../BottomSheetNavigationController.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sources/BottomSheet/Core/NavigationController/BottomSheetNavigationController.swift b/Sources/BottomSheet/Core/NavigationController/BottomSheetNavigationController.swift index bb7d297..9675f64 100644 --- a/Sources/BottomSheet/Core/NavigationController/BottomSheetNavigationController.swift +++ b/Sources/BottomSheet/Core/NavigationController/BottomSheetNavigationController.swift @@ -26,6 +26,11 @@ public final class BottomSheetNavigationController: UINavigationController { super.init(rootViewController: rootViewController) } + override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { + self.configuration = .default + super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) + } + @available(*, unavailable) required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented")