diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 64273fe406..1ddb552cc0 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -78,6 +78,23 @@ :handler (:handler command)}] (commands/stage-command db command-info)))) +(register-handler :set-message-input [] + (fn [db [_ input]] + (assoc db :message-input input))) + +(register-handler :prepare-message-input + (u/side-effect! + (fn [db _] + (when-let [message-input (:message-input db)] + (.clear message-input) + (.focus message-input))))) + +(register-handler :blur-message-input + (u/side-effect! + (fn [db _] + (when-let [message-input (:message-input db)] + (.blur message-input))))) + (register-handler :set-response-chat-command (after #(dispatch [:animate-show-response])) (fn [db [_ to-msg-id command-key]] diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index 3afb86c24b..b3f540282a 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -15,16 +15,16 @@ (assoc-in db [:animations :commands-input-is-switching?] false))) (register-handler :animate-cancel-command - (path :animations) - (fn [db _] - (if-not (:commands-input-is-switching? db) - (assoc db - :commands-input-is-switching? true - :message-input-buttons-scale 1 - :message-input-offset 0 - :to-response-height zero-height - :messages-offset 0) - db))) + (path :animations) + (fn [db _] + (if-not (:commands-input-is-switching? db) + (assoc db + :commands-input-is-switching? true + :message-input-buttons-scale 1 + :message-input-offset 0 + :to-response-height zero-height + :messages-offset 0) + db))) (register-handler :finish-animate-response-resize (fn [db _] @@ -56,12 +56,13 @@ (assoc-in db [:animations :to-response-height] (get-response-height db))) (register-handler :finish-show-response + (after #(dispatch [:prepare-message-input])) (fn [db _] (assoc-in db [:animations :commands-input-is-switching?] false))) (register-handler :animate-show-response + (after #(dispatch [:animate-response-resize])) (fn [db _] - (dispatch [:animate-response-resize]) (-> db (assoc-in [:animations :commands-input-is-switching?] true) (assoc-in [:animations :response-height-current] zero-height) diff --git a/src/status_im/chat/views/plain_input.cljs b/src/status_im/chat/views/plain_input.cljs index b92c7f6521..da0e88648d 100644 --- a/src/status_im/chat/views/plain_input.cljs +++ b/src/status_im/chat/views/plain_input.cljs @@ -146,19 +146,22 @@ message-input? st/message-input response? st-response/command-input command st-command/command-input) + :ref (fn [input] + (dispatch [:set-message-input input])) :autoFocus false :blurOnSubmit dismiss-keyboard :onChangeText (fn [text] - ((if message-input? - set-input-message - command/set-input-message) - text)) - :editable (not animation?) - :onSubmitEditing #(if message-input? - (try-send staged-commands - input-message - dismiss-keyboard) - (command/try-send input-command validator))} + (when-not animation? + ((if message-input? + set-input-message + command/set-input-message) + text))) + :onSubmitEditing #(when-not animation? + (if message-input? + (try-send staged-commands + input-message + dismiss-keyboard) + (command/try-send input-command validator)))} (when command {:accessibility-label :command-input}) input-options)