diff --git a/VDSSample/ViewControllers/BaseViewController.swift b/VDSSample/ViewControllers/BaseViewController.swift index 3c31212..46526d9 100644 --- a/VDSSample/ViewControllers/BaseViewController.swift +++ b/VDSSample/ViewControllers/BaseViewController.swift @@ -261,6 +261,21 @@ public class BaseViewController: UIViewController, Initable , loadCustomRotors() UIAccessibility.post(notification: .screenChanged, argument: component) } + + if component.canBecomeFirstResponder { + let tapGesture = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard)) + tapGesture.cancelsTouchesInView = false // This allows the tap to pass through to other views. + view.addGestureRecognizer(tapGesture) + } + } + + @objc func dismissKeyboard(_ sender: UITapGestureRecognizer) { + let location = sender.location(in: self.view) + + // Check if the touch is outside the textView + if !component.frame.contains(location) { + component.resignFirstResponder() + } } func isViewHiddenByKeyboard(view: UIView, keyboardFrame: CGRect) -> Bool {