Procházet zdrojové kódy

keep keyboard after pressing the send button

cyberta před 4 roky
rodič
revize
65c638397a
1 změnil soubory, kde provedl 18 přidání a 0 odebrání
  1. 18 0
      deltachat-ios/Chat/ChatViewController.swift

+ 18 - 0
deltachat-ios/Chat/ChatViewController.swift

@@ -25,6 +25,7 @@ class ChatViewController: UITableViewController {
     var isInitial = true
     var ignoreInputBarChange = false
     private var isVisibleToUser: Bool = false
+    private var keepKeyboard: Bool = false
 
     lazy var isGroupChat: Bool = {
         return dcContext.getChat(chatId: chatId).isGroup
@@ -858,6 +859,7 @@ class ChatViewController: UITableViewController {
         messageInputBar.inputTextView.layer.masksToBounds = true
         messageInputBar.inputTextView.scrollIndicatorInsets = UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0)
         configureInputBarItems()
+        messageInputBar.inputTextView.delegate = self
     }
 
     private func evaluateInputBar(draft: DraftModel) {
@@ -1453,6 +1455,7 @@ extension ChatViewController: MediaPickerDelegate {
 // MARK: - MessageInputBarDelegate
 extension ChatViewController: InputBarAccessoryViewDelegate {
     func inputBar(_ inputBar: InputBarAccessoryView, didPressSendButtonWith text: String) {
+        keepKeyboard = true
         let trimmedText = text.replacingOccurrences(of: "\u{FFFC}", with: "", options: .literal, range: nil)
             .trimmingCharacters(in: .whitespacesAndNewlines)
         if let filePath = draft.attachment, let viewType = draft.viewType {
@@ -1570,3 +1573,18 @@ extension ChatViewController: AudioControllerDelegate {
         self.present(alert, animated: true, completion: nil)
     }
 }
+
+// MARK: - UITextViewDelegate
+extension ChatViewController: UITextViewDelegate {
+    func textViewShouldEndEditing(_ textView: UITextView) -> Bool {
+        if keepKeyboard {
+            DispatchQueue.main.async { [weak self] in
+                self?.messageInputBar.inputTextView.becomeFirstResponder()
+            }
+            keepKeyboard = false
+            return false
+        }
+        
+        return true
+    }
+}