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

Convenience dismiss & canBeDismissed handler. Fix iOS 12 crash #22

Merged
merged 2 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down