From f03c6cc0818386c17c61f3ea82b10a17b7193e65 Mon Sep 17 00:00:00 2001 From: Tanguy Helesbeux Date: Tue, 30 May 2023 11:35:20 +0200 Subject: [PATCH] [iOS SDK] Tap to close keyboard (#27104) - Fixes: https://nabla-tech.slack.com/archives/C04ENMXR93J/p1685402302117649 ## Summary Keep the interactive dismiss, but add tap to close. ### Changelog - Messaging UI: Users can tap any where on the conversation screen to close the keyboard. ## Test plan https://github.com/nabla/health/assets/2571118/fa824d4d-4da0-42e5-a250-40ab661545c3 --- CHANGELOG.md | 2 ++ .../Conversation/UI/ConversationViewController.swift | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28776005..f3e811f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Messaging UI: Users can tap any where on the conversation screen to close the keyboard. + ### Fixed diff --git a/Sources/NablaMessagingUI/Scenes/Conversation/UI/ConversationViewController.swift b/Sources/NablaMessagingUI/Scenes/Conversation/UI/ConversationViewController.swift index cc010eae..056276fb 100644 --- a/Sources/NablaMessagingUI/Scenes/Conversation/UI/ConversationViewController.swift +++ b/Sources/NablaMessagingUI/Scenes/Conversation/UI/ConversationViewController.swift @@ -180,6 +180,16 @@ final class ConversationViewController: UIViewController, ConversationViewContra // TODO: @tgy - Don't retain modules private lazy var imagePickerModule = ImagePickerModule(delegate: self) + private lazy var tapGesture: UIGestureRecognizer = { + let recognizer = UITapGestureRecognizer(target: self, action: #selector(tapGestureHandler)) + recognizer.cancelsTouchesInView = false + return recognizer + }() + + @objc private func tapGestureHandler() { + view.endEditing(true) + } + private func initialize() { hidesBottomBarWhenPushed = true @@ -191,6 +201,8 @@ final class ConversationViewController: UIViewController, ConversationViewContra ?? UINavigationBarAppearance() scrollEdgeAppearance.configureWithDefaultBackground() navigationItem.scrollEdgeAppearance = scrollEdgeAppearance + + collectionView.addGestureRecognizer(tapGesture) } private func setUp() {