From 49b08e51181249addc5f50f0d0d866836f8e1944 Mon Sep 17 00:00:00 2001 From: virvar Date: Wed, 25 May 2016 14:50:52 +0300 Subject: [PATCH] Don't dismiss keyboard on command input appear --- src/status_im/chat/views/plain_input.cljs | 100 ++++++++++++---------- 1 file changed, 54 insertions(+), 46 deletions(-) diff --git a/src/status_im/chat/views/plain_input.cljs b/src/status_im/chat/views/plain_input.cljs index f3ee1f9fa9..7ff822da85 100644 --- a/src/status_im/chat/views/plain_input.cljs +++ b/src/status_im/chat/views/plain_input.cljs @@ -4,7 +4,8 @@ [status-im.components.react :refer [view icon touchable-highlight - text-input]] + text-input + dismiss-keyboard!]] [status-im.chat.views.suggestions :refer [suggestions-view]] [status-im.chat.views.content-suggestions :refer [content-suggestions-view]] [status-im.chat.views.command :as command] @@ -14,7 +15,9 @@ (defn set-input-message [message] (dispatch [:set-chat-input-text message])) -(defn send [] +(defn send [dismiss-keyboard] + (when dismiss-keyboard + (dismiss-keyboard!)) (dispatch [:send-chat-msg])) (defn message-valid? [staged-commands message] @@ -22,9 +25,9 @@ (not= "!" message)) (pos? (count staged-commands)))) -(defn try-send [staged-commands message] +(defn try-send [staged-commands message dismiss-keyboard] (when (message-valid? staged-commands message) - (send))) + (send dismiss-keyboard))) (defn plain-message-input-view [{:keys [command input-options validator]}] (let [input-message (subscribe [:get-chat-input-text]) @@ -32,46 +35,51 @@ staged-commands (subscribe [:get-chat-staged-commands]) typing-command? (subscribe [:typing-command?])] (fn [{:keys [command input-options validator]}] - [view st/input-container - (if command - [content-suggestions-view] - [suggestions-view]) - [view st/input-view - (if command - [command/command-icon command] - [touchable-highlight {:on-press #(dispatch [:switch-command-suggestions]) - :style st/switch-commands-touchable} - [view nil - (if @typing-command? - [icon :close-gray st/close-icon] - [icon :list st/list-icon])]]) - [text-input (merge {:style (if command st-command/command-input st/message-input) ;; st-command/command-input - :autoFocus false - :onChangeText (fn [text] - ((if command - command/set-input-message - set-input-message) - text)) - :onSubmitEditing (fn [] - (if command - (command/try-send @input-command validator) - (try-send @staged-commands - @input-message)))} - input-options) + (let [dismiss-keyboard (not (or command @typing-command?))] + [view st/input-container (if command - @input-command - @input-message)] - ;; TODO emoticons: not implemented - (when (not command) - [icon :smile st/smile-icon]) - (if command - (if (command/valid? @input-command validator) - [touchable-highlight {:on-press command/send-command} - [view st/send-container [icon :send st/send-icon]]] - [touchable-highlight {:on-press command/cancel-command-input} - [view st-command/cancel-container - [icon :close-gray st-command/cancel-icon]]]) - (when (message-valid? @staged-commands @input-message) - [touchable-highlight {:on-press send} - [view st/send-container - [icon :send st/send-icon]]]))]]))) + [content-suggestions-view] + [suggestions-view]) + [view st/input-view + (if command + [command/command-icon command] + [touchable-highlight {:on-press #(dispatch [:switch-command-suggestions]) + :style st/switch-commands-touchable} + [view nil + (if @typing-command? + [icon :close-gray st/close-icon] + [icon :list st/list-icon])]]) + [text-input (merge {:style (if command st-command/command-input st/message-input) ;; st-command/command-input + :autoFocus false + :blurOnSubmit dismiss-keyboard + :onChangeText (fn [text] + ((if command + command/set-input-message + set-input-message) + text)) + :onSubmitEditing (fn [] + (if command + (command/try-send @input-command validator) + (try-send @staged-commands + @input-message + dismiss-keyboard)))} + input-options) + (if command + @input-command + @input-message)] + ;; TODO emoticons: not implemented + (when (not command) + [icon :smile st/smile-icon]) + (if command + (if (command/valid? @input-command validator) + [touchable-highlight {:on-press command/send-command} + [view st/send-container [icon :send st/send-icon]]] + [touchable-highlight {:on-press command/cancel-command-input} + [view st-command/cancel-container + [icon :close-gray st-command/cancel-icon]]]) + (when (message-valid? @staged-commands @input-message) + [touchable-highlight {:on-press #(try-send @staged-commands + @input-message + dismiss-keyboard)} + [view st/send-container + [icon :send st/send-icon]]]))]]))))