diff --git a/Display/ActionSheetController.swift b/Display/ActionSheetController.swift index 6acc6fdcfe..6f6ff08e7c 100644 --- a/Display/ActionSheetController.swift +++ b/Display/ActionSheetController.swift @@ -17,6 +17,8 @@ open class ActionSheetController: ViewController { private var isDismissed: Bool = false + public var dismissed: ((Bool) -> Void)? + public init(theme: ActionSheetControllerTheme) { self.theme = theme @@ -30,7 +32,7 @@ open class ActionSheetController: ViewController { public func dismissAnimated() { if !self.isDismissed { self.isDismissed = true - self.actionSheetNode.animateOut() + self.actionSheetNode.animateOut(cancelled: false) } } @@ -38,7 +40,8 @@ open class ActionSheetController: ViewController { self.displayNode = ActionSheetControllerNode(theme: self.theme) self.displayNodeDidLoad() - self.actionSheetNode.dismiss = { [weak self] in + self.actionSheetNode.dismiss = { [weak self] cancelled in + self?.dismissed?(cancelled) self?.presentingViewController?.dismiss(animated: false) } diff --git a/Display/ActionSheetControllerNode.swift b/Display/ActionSheetControllerNode.swift index ec2f67c6a5..7d03e0996f 100644 --- a/Display/ActionSheetControllerNode.swift +++ b/Display/ActionSheetControllerNode.swift @@ -28,7 +28,7 @@ final class ActionSheetControllerNode: ASDisplayNode, UIScrollViewDelegate { private let scrollView: UIScrollView - var dismiss: () -> Void = { } + var dismiss: (Bool) -> Void = { _ in } private var validLayout: ContainerViewLayout? @@ -127,7 +127,7 @@ final class ActionSheetControllerNode: ASDisplayNode, UIScrollViewDelegate { }) } - func animateOut() { + func animateOut(cancelled: Bool) { let tempDimView = UIView() tempDimView.backgroundColor = self.theme.dimColor tempDimView.frame = self.bounds.offsetBy(dx: 0.0, dy: -self.bounds.size.height) @@ -141,7 +141,7 @@ final class ActionSheetControllerNode: ASDisplayNode, UIScrollViewDelegate { self.layer.animateBounds(from: self.bounds, to: self.bounds.offsetBy(dx: 0.0, dy: -self.bounds.size.height), duration: 0.35, timingFunction: kCAMediaTimingFunctionEaseOut, removeOnCompletion: false, completion: { [weak self, weak tempDimView] _ in tempDimView?.removeFromSuperview() - self?.dismiss() + self?.dismiss(cancelled) }) } @@ -152,7 +152,7 @@ final class ActionSheetControllerNode: ASDisplayNode, UIScrollViewDelegate { @objc func dimNodeTap(_ recognizer: UITapGestureRecognizer) { if case .ended = recognizer.state { - self.animateOut() + self.animateOut(cancelled: true) } } @@ -174,7 +174,7 @@ final class ActionSheetControllerNode: ASDisplayNode, UIScrollViewDelegate { let additionalTopHeight = max(0.0, -contentOffset.y) if additionalTopHeight >= 30.0 { - self.animateOut() + self.animateOut(cancelled: true) } }