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( 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")