From 02f264251f858638546bbbf89db7b646eb227431 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 20 Jun 2016 20:31:14 +0300 Subject: [PATCH] fix input Former-commit-id: d298a142f7ed7f1376d7ab33d3fd91c6ea200752 --- src/status_im/chat/screen.cljs | 4 +- src/status_im/chat/views/message_input.cljs | 50 +++++++++------------ src/status_im/chat/views/new_message.cljs | 11 ++--- 3 files changed, 29 insertions(+), 36 deletions(-) diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index feb88de74e..2c04ab4859 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -259,6 +259,7 @@ [group-chat [:chat :group-chat] show-actions-atom [:show-actions] command [:get-chat-command] + command? [:animations :command?] to-msg-id [:get-chat-command-to-msg-id]] [view {:style st/chat-view :onLayout (fn [event] @@ -269,8 +270,7 @@ [messages-view group-chat]] (when group-chat [typing-all]) (cond - (and command to-msg-id) [response-view] - command [content-suggestions-view] + command? [response-view] :else [suggestions-view]) [chat-message-new] (when show-actions-atom [actions-view])]) diff --git a/src/status_im/chat/views/message_input.cljs b/src/status_im/chat/views/message_input.cljs index d3bf3eccc8..3dc34d8e1a 100644 --- a/src/status_im/chat/views/message_input.cljs +++ b/src/status_im/chat/views/message_input.cljs @@ -39,48 +39,42 @@ (defview message-input [input-options validator] [input-message [:get-chat-input-text] command [:get-chat-command] + command? [:animations :command?] to-msg-id [:get-chat-command-to-msg-id] input-command [:get-chat-command-content] staged-commands [:get-chat-staged-commands] typing-command? [:typing-command?]] - (let [dismiss-keyboard (not (or command typing-command?)) - response? (and command to-msg-id) - message-input? (not command)] - [text-input (merge {:style (cond - message-input? st-message/message-input - response? st-response/command-input - command st-command/command-input) - :ref (fn [input] - (dispatch [:set-message-input input])) + (let [dismiss-keyboard (not (or command typing-command?))] + [text-input (merge {:style (if command? + st-response/command-input + st-message/message-input) + :ref #(dispatch [:set-message-input %]) :autoFocus false :blurOnSubmit dismiss-keyboard - :onChangeText (fn [text] - ((if message-input? - plain-message/set-input-message - command/set-input-message) - text)) - :onSubmitEditing #(if message-input? + :onChangeText (if command? + command/set-input-message + plain-message/set-input-message) + :onSubmitEditing #(if command? + (command/try-send input-command validator) (plain-message/try-send staged-commands input-message - dismiss-keyboard) - (command/try-send input-command validator))} - (when command + dismiss-keyboard))} + (when command? {:accessibility-label :command-input}) input-options) - (if message-input? - input-message - input-command)])) + (if command? + input-command + input-message)])) (defview plain-message-input-view [{:keys [input-options validator]}] [input-message [:get-chat-input-text] command [:get-chat-command] + command? [:animations :command?] to-msg-id [:get-chat-command-to-msg-id] input-command [:get-chat-command-content] staged-commands [:get-chat-staged-commands] typing-command? [:typing-command?]] - (let [dismiss-keyboard (not (or command typing-command?)) - response? (and command to-msg-id) - message-input? (not command)] + (let [dismiss-keyboard (not (or command typing-command?))] [view st/input-container [view st/input-view [plain-message/commands-button] @@ -88,14 +82,12 @@ [message-input input-options validator]] ;; TODO emoticons: not implemented [plain-message/smile-button] - (if message-input? + (if-not command? (when (plain-message/message-valid? staged-commands input-message) [send-button {:on-press #(plain-message/try-send staged-commands input-message dismiss-keyboard) :accessibility-label :send-message}]) - (if (command/valid? input-command validator) + (when (command/valid? input-command validator) [send-button {:on-press command/send-command - :accessibility-label :stage-command}] - (when-not response? - [command/cancel-button])))]])) + :accessibility-label :stage-command}]))]])) diff --git a/src/status_im/chat/views/new_message.cljs b/src/status_im/chat/views/new_message.cljs index 3a330d0a0b..e8e53d2681 100644 --- a/src/status_im/chat/views/new_message.cljs +++ b/src/status_im/chat/views/new_message.cljs @@ -16,9 +16,11 @@ (for [command staged-commands] ^{:key command} [staged-command-view command])]) -(defn show-input [command] +(defview show-input [] + [command [:get-chat-command] + command? [:animations :command?]] [plain-message-input-view - (when command + (when command? (case (:command command) :phone {:input-options {:keyboardType :phone-pad} :validator valid-mobile-number?} @@ -29,9 +31,8 @@ (throw (js/Error. "Uknown command type"))))]) (defview chat-message-new [] - [command [:get-chat-command] - staged-commands [:get-chat-staged-commands]] + [staged-commands [:get-chat-staged-commands]] [view st/new-message-container (when (and staged-commands (pos? (count staged-commands))) [staged-commands-view staged-commands]) - [show-input command]]) + [show-input]])