From e070661ae3f256315b95b6c07cbfdd1a81e63467 Mon Sep 17 00:00:00 2001 From: alwx Date: Tue, 14 Feb 2017 13:44:08 +0300 Subject: [PATCH] Persist Keyboard when typing command and moving to parameters (#776) --- src/status_im/chat/handlers/commands.cljs | 5 +- src/status_im/chat/views/message_input.cljs | 89 ++++++++++++--------- src/status_im/chat/views/new_message.cljs | 18 +---- src/status_im/chat/views/response.cljs | 3 +- src/status_im/commands/handlers/jail.cljs | 7 +- 5 files changed, 58 insertions(+), 64 deletions(-) diff --git a/src/status_im/chat/handlers/commands.cljs b/src/status_im/chat/handlers/commands.cljs index 2ec4c6d099..35257cac20 100644 --- a/src/status_im/chat/handlers/commands.cljs +++ b/src/status_im/chat/handlers/commands.cljs @@ -1,6 +1,7 @@ (ns status-im.chat.handlers.commands (:require [re-frame.core :refer [enrich after dispatch]] [status-im.utils.handlers :refer [register-handler] :as u] + [status-im.components.react :as react-comp] [status-im.components.status :as status] [status-im.models.commands :as commands] [status-im.chat.utils :refer [console? not-console?]] @@ -295,7 +296,9 @@ (fn [_ [_ {:keys [command]}]] (let [suggestions-trigger (keyword (:suggestions-trigger command))] (if (= :on-send suggestions-trigger) - (dispatch [:invoke-commands-suggestions!]) + (do + (dispatch [:invoke-commands-suggestions!]) + (react-comp/dismiss-keyboard!)) (do (dispatch [:set-chat-ui-props :sending-disabled? true]) (dispatch [:validate-command]))))))) diff --git a/src/status_im/chat/views/message_input.cljs b/src/status_im/chat/views/message_input.cljs index dcd598e33a..90cf18ad65 100644 --- a/src/status_im/chat/views/message_input.cljs +++ b/src/status_im/chat/views/message_input.cljs @@ -14,7 +14,8 @@ [status-im.chat.styles.response :as st-response] [status-im.accessibility-ids :as id] [reagent.core :as r] - [clojure.string :as str])) + [clojure.string :as str] + [taoensso.timbre :as log])) (defn send-button [{:keys [on-press accessibility-label]}] [touchable-highlight {:on-press on-press @@ -36,46 +37,58 @@ (when-not sending-disabled? (dispatch [:send-command!])))}) -(defview message-input [input-options set-layout-size] - [input-message [:get-chat-input-text] - disable? [:get :disable-input] - active? [:chat :is-active]] - [text-input (merge - (plain-input-options (or disable? (not active?))) - {:placeholder-text-color :#c0c5c9 - :auto-focus false - :blur-on-submit true - :multiline true - :on-content-size-change #(let [size (-> (.-nativeEvent %) - (.-contentSize) - (.-height))] - (set-layout-size size)) - :accessibility-label id/chat-message-input - :on-focus #(do (dispatch [:set :focused true]) - (dispatch [:set-chat-ui-props :show-emoji? false])) - :on-blur #(do (dispatch [:set :focused false]) - (set-layout-size 0)) - :default-value (or input-message "")} - input-options)]) +(defn get-options [{:keys [type placeholder]} command-type] + (let [options (case (keyword type) + :phone {:keyboard-type "phone-pad"} + :password {:secure-text-entry true} + :number {:keyboard-type "numeric"} + nil)] + (if (= :response command-type) + (if placeholder + (assoc options :placeholder placeholder) + options) + (assoc options :placeholder "")))) -(defview command-input [input-options {:keys [fullscreen]} sending-disabled?] - [input-command [:get-chat-command-content] +(defview message-input [set-layout-size] + [input-message [:get-chat-input-text] + input-command [:get-chat-command-content] + command [:get-chat-command] icon-width [:command-icon-width] - disable? [:get :disable-input]] - [text-input (merge - (command-input-options icon-width disable? sending-disabled?) - {:auto-focus (not fullscreen) - :blur-on-submit false - :accessibility-label id/chat-message-input - :on-focus #(dispatch [:set :focused true]) - :on-blur #(dispatch [:set :focused false]) - :default-value (or input-command "")} - input-options)]) + disable? [:get :disable-input] + active? [:chat :is-active] + command? [:command?] + parameter [:get-command-parameter] + type [:command-type] + sending-disabled? [:chat-ui-props :sending-disabled?]] + [text-input + (merge + (if command? + (command-input-options icon-width disable? sending-disabled?) + (plain-input-options (or disable? (not active?)))) + {:placeholder-text-color :#c0c5c9 + :auto-focus (when command? + (not (:fullscreen command))) + :blur-on-submit false + :multiline true + :on-content-size-change #(let [size (-> (.-nativeEvent %) + (.-contentSize) + (.-height))] + (set-layout-size size)) + :accessibility-label id/chat-message-input + :on-focus #(do (dispatch [:set :focused true]) + (dispatch [:set-chat-ui-props :show-emoji? false])) + :on-blur #(do (dispatch [:set :focused false]) + (set-layout-size 0)) + :default-value (if command? + (or input-command "") + (or input-message ""))} + (when command? + (get-options parameter type)))]) (defn plain-message-get-initial-state [_] {:height 0}) -(defn plain-message-input-view [_] +(defn plain-message-input-view [] (let [command? (subscribe [:command?]) command (subscribe [:get-chat-command]) input-command (subscribe [:get-chat-command-content]) @@ -93,15 +106,13 @@ (and (not @command?) (not @input-message))) (set-layout-size 0))) :reagent-render - (fn [{:keys [input-options]}] + (fn [] (let [{:keys [height]} (r/state component)] [view st/input-container [view (st/input-view height) [plain-message/commands-button height #(set-layout-size 0)] [view (st/message-input-container height) - (if @command? - [command-input input-options @command @sending-disabled?] - [message-input input-options set-layout-size])] + [message-input set-layout-size]] [plain-message/smile-button height] (when (or (and @command? (not (str/blank? @input-command))) @valid-plain-message?) diff --git a/src/status_im/chat/views/new_message.cljs b/src/status_im/chat/views/new_message.cljs index ee0ae5f947..4eee8c014f 100644 --- a/src/status_im/chat/views/new_message.cljs +++ b/src/status_im/chat/views/new_message.cljs @@ -12,25 +12,10 @@ (defn get-height [event] (.-height (.-layout (.-nativeEvent event)))) -(defn get-options [{:keys [type placeholder]} command-type] - (let [options (case (keyword type) - :phone {:input-options {:keyboard-type "phone-pad"}} - :password {:input-options {:secure-text-entry true}} - :number {:input-options {:keyboard-type "numeric"}} - ;; todo maybe nil is fine for now :) - nil #_(throw (js/Error. "Unknown command type")))] - (if (= :response command-type) - (if placeholder - (assoc-in options [:input-options :placeholder] placeholder) - options) - (assoc-in options [:input-options :placeholder] "")))) - (defview chat-message-input-view [] [margin [:input-margin] command? [:command?] response-height [:response-height] - parameter [:get-command-parameter] - type [:command-type] suggestions [:get-suggestions] message-input-height [:get-message-input-view-height]] (let [on-top? (or (and (seq suggestions) (not command?)) @@ -41,5 +26,4 @@ (let [height (get-height event)] (when (not= height message-input-height) (dispatch [:set-message-input-view-height height]))))} - [plain-message-input-view - (when command? (get-options parameter type))]])) + [plain-message-input-view]])) diff --git a/src/status_im/chat/views/response.cljs b/src/status_im/chat/views/response.cljs index 3715238f6b..9ccbd22182 100644 --- a/src/status_im/chat/views/response.cljs +++ b/src/status_im/chat/views/response.cljs @@ -25,7 +25,8 @@ [status-im.utils.datetime :as dt] [status-im.utils.name :refer [shortened-name]] [status-im.utils.js-resources :as js-res] - [status-im.commands.utils :as cu])) + [status-im.commands.utils :as cu] + [taoensso.timbre :as log])) (defn drag-icon [] [view st/drag-container diff --git a/src/status_im/commands/handlers/jail.cljs b/src/status_im/commands/handlers/jail.cljs index b87f16b6a4..e5dddf6e5a 100644 --- a/src/status_im/commands/handlers/jail.cljs +++ b/src/status_im/commands/handlers/jail.cljs @@ -81,12 +81,7 @@ (reg-handler :suggestions-handler [(after #(dispatch [:animate-show-response])) - (after (print-error-message! "Error on param suggestions")) - (after (fn [_ [{:keys [command]}]] - (when (= :on-send (keyword (:suggestions-trigger command))) - #_(when (:webViewUrl (:returned result)) - (dispatch [:set-soft-input-mode :pan])) - (r/dismiss-keyboard!))))] + (after (print-error-message! "Error on param suggestions"))] suggestions-handler!) (reg-handler :suggestions-event! (u/side-effect! suggestions-events-handler!))