From 1ca4fdf794998c569c6dc30a9bbd048f257de60c Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 30 Jun 2023 09:17:23 -0500 Subject: [PATCH] added swipe right and tap background events for dismissing self Signed-off-by: Matt Bruce --- .../Tooltip/TooltipAlertViewController.swift | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/VDS/Components/Tooltip/TooltipAlertViewController.swift b/VDS/Components/Tooltip/TooltipAlertViewController.swift index aa59f58e..da4e1e90 100644 --- a/VDS/Components/Tooltip/TooltipAlertViewController.swift +++ b/VDS/Components/Tooltip/TooltipAlertViewController.swift @@ -12,6 +12,9 @@ import VDSColorTokens open class TooltipAlertViewController: UIViewController, Surfaceable { + /// Set of Subscribers for any Publishers for this Control + public var subscribers = Set() + //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- @@ -60,10 +63,6 @@ open class TooltipAlertViewController: UIViewController, Surfaceable { button.setTitle("Close", for: .normal) button.titleLabel?.font = TextStyle.bodyLarge.font button.translatesAutoresizingMaskIntoConstraints = false - onClickSubscriber = button.publisher(for: .touchUpInside).sink {[weak self] button in - guard let self else { return } - self.dismiss(animated: true, completion: nil) - } return button }() @@ -90,6 +89,28 @@ open class TooltipAlertViewController: UIViewController, Surfaceable { } open func setup() { + + //left-right swipe + view.publisher(for: UISwipeGestureRecognizer().with{ $0.direction = .right }) + .sink { [weak self] swipe in + guard let self else { return } + self.dismiss(animated: true, completion: nil) + }.store(in: &subscribers) + + //tapping in background + view.publisher(for: UITapGestureRecognizer().with{ $0.numberOfTapsRequired = 1 }) + .sink { [weak self] swipe in + guard let self else { return } + self.dismiss(animated: true, completion: nil) + }.store(in: &subscribers) + + //clicking button + onClickSubscriber = closeButton.publisher(for: .touchUpInside) + .sink {[weak self] button in + guard let self else { return } + self.dismiss(animated: true, completion: nil) + } + containerView.addSubview(titleLabel) containerView.addSubview(contentLabel) scrollView.addSubview(containerView)