From c8e303810f77ba042a25a8402ee7c6e58906a5cf Mon Sep 17 00:00:00 2001 From: Andrew Balmer Date: Tue, 29 Oct 2024 17:03:26 -0400 Subject: [PATCH] added tap gesture recognizer --- .../KlaviyoWebWrapperViewController.swift | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebWrapperViewController.swift b/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebWrapperViewController.swift index 4f9183b2..5e084d13 100644 --- a/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebWrapperViewController.swift +++ b/Sources/KlaviyoUI/KlaviyoWebView/KlaviyoWebWrapperViewController.swift @@ -14,6 +14,13 @@ public class KlaviyoWebWrapperViewController: UIViewController { let viewModel: KlaviyoWebViewModeling let style: KlaviyoWebWrapperStyle + private lazy var dismissGestureRecognizer: UITapGestureRecognizer = { + let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleDismissGesture)) + tapRecognizer.numberOfTapsRequired = 1 + tapRecognizer.numberOfTouchesRequired = 1 + return tapRecognizer + }() + // MARK: - Subviews private lazy var blurEffectView: UIVisualEffectView? = { @@ -22,6 +29,8 @@ public class KlaviyoWebWrapperViewController: UIViewController { let blurEffect = UIBlurEffect(style: effect) let blurEffectView = UIVisualEffectView(effect: blurEffect) + blurEffectView.addGestureRecognizer(dismissGestureRecognizer) + return blurEffectView }() @@ -32,6 +41,8 @@ public class KlaviyoWebWrapperViewController: UIViewController { tintView.backgroundColor = color tintView.layer.opacity = opacity + tintView.addGestureRecognizer(dismissGestureRecognizer) + return tintView }() @@ -110,6 +121,12 @@ public class KlaviyoWebWrapperViewController: UIViewController { webViewController.didMove(toParent: self) } } + + // MARK: - user interactions + + @objc private func handleDismissGesture() { + viewModel.dismiss() + } } // MARK: - Previews