diff --git a/Sources/Addons/BottomSheet/Interaction/Interactions/BottomSheetPresentedInteraction.swift b/Sources/Addons/BottomSheet/Interaction/Interactions/BottomSheetPresentedInteraction.swift index a5c116b7..265a7d16 100644 --- a/Sources/Addons/BottomSheet/Interaction/Interactions/BottomSheetPresentedInteraction.swift +++ b/Sources/Addons/BottomSheet/Interaction/Interactions/BottomSheetPresentedInteraction.swift @@ -111,9 +111,7 @@ internal final class BottomSheetPresentedInteraction: BottomSheetInteraction { .transition .wantsInteractiveStart = !isGestureFinished - presentationController - .presentingViewController - .dismiss(animated: true) + presentationController.dismissPresentedViewController() } internal func start( diff --git a/Sources/Addons/BottomSheet/Presentation/BottomSheetPresentationController.swift b/Sources/Addons/BottomSheet/Presentation/BottomSheetPresentationController.swift index 8f9ffa24..965d5bb1 100644 --- a/Sources/Addons/BottomSheet/Presentation/BottomSheetPresentationController.swift +++ b/Sources/Addons/BottomSheet/Presentation/BottomSheetPresentationController.swift @@ -305,9 +305,15 @@ internal final class BottomSheetPresentationController: UIPresentationController } @objc private func onDimmingViewTapGesture() { - if delegate?.presentationControllerShouldDismiss?(self) ?? true { - presentingViewController.dismiss(animated: true) + guard state == .presented else { + return + } + + guard delegate?.presentationControllerShouldDismiss?(self) ?? true else { + return } + + dismissPresentedViewController() } @objc private func onTransitionViewPanGesture(recognizer: UIPanGestureRecognizer) { @@ -474,6 +480,16 @@ internal final class BottomSheetPresentationController: UIPresentationController animator.startAnimation() } + internal func dismissPresentedViewController() { + delegate?.presentationControllerWillDismiss?(self) + + presentingViewController.dismiss(animated: true) { + if self.state == .dismissed { + self.delegate?.presentationControllerDidDismiss?(self) + } + } + } + internal override func presentationTransitionWillBegin() { super.presentationTransitionWillBegin() @@ -506,8 +522,6 @@ internal final class BottomSheetPresentationController: UIPresentationController internal override func dismissalTransitionWillBegin() { super.dismissalTransitionWillBegin() - delegate?.presentationControllerWillDismiss?(self) - animateChangesAlongsideTransition { self.dimmingView?.alpha = .zero } @@ -521,8 +535,6 @@ internal final class BottomSheetPresentationController: UIPresentationController transition.wantsInteractiveStart = false if completed { - delegate?.presentationControllerDidDismiss?(self) - dimmingView?.removeFromSuperview() transitionView?.removeFromSuperview()