Persist Keyboard when typing command and moving to parameters (#776)

This commit is contained in:
alwx 2017-02-14 13:44:08 +03:00 committed by Roman Volosovskyi
parent 27ddb24f7b
commit e070661ae3
5 changed files with 58 additions and 64 deletions

View File

@ -1,6 +1,7 @@
(ns status-im.chat.handlers.commands (ns status-im.chat.handlers.commands
(:require [re-frame.core :refer [enrich after dispatch]] (:require [re-frame.core :refer [enrich after dispatch]]
[status-im.utils.handlers :refer [register-handler] :as u] [status-im.utils.handlers :refer [register-handler] :as u]
[status-im.components.react :as react-comp]
[status-im.components.status :as status] [status-im.components.status :as status]
[status-im.models.commands :as commands] [status-im.models.commands :as commands]
[status-im.chat.utils :refer [console? not-console?]] [status-im.chat.utils :refer [console? not-console?]]
@ -295,7 +296,9 @@
(fn [_ [_ {:keys [command]}]] (fn [_ [_ {:keys [command]}]]
(let [suggestions-trigger (keyword (:suggestions-trigger command))] (let [suggestions-trigger (keyword (:suggestions-trigger command))]
(if (= :on-send suggestions-trigger) (if (= :on-send suggestions-trigger)
(do
(dispatch [:invoke-commands-suggestions!]) (dispatch [:invoke-commands-suggestions!])
(react-comp/dismiss-keyboard!))
(do (do
(dispatch [:set-chat-ui-props :sending-disabled? true]) (dispatch [:set-chat-ui-props :sending-disabled? true])
(dispatch [:validate-command]))))))) (dispatch [:validate-command])))))))

View File

@ -14,7 +14,8 @@
[status-im.chat.styles.response :as st-response] [status-im.chat.styles.response :as st-response]
[status-im.accessibility-ids :as id] [status-im.accessibility-ids :as id]
[reagent.core :as r] [reagent.core :as r]
[clojure.string :as str])) [clojure.string :as str]
[taoensso.timbre :as log]))
(defn send-button [{:keys [on-press accessibility-label]}] (defn send-button [{:keys [on-press accessibility-label]}]
[touchable-highlight {:on-press on-press [touchable-highlight {:on-press on-press
@ -36,15 +37,38 @@
(when-not sending-disabled? (when-not sending-disabled?
(dispatch [:send-command!])))}) (dispatch [:send-command!])))})
(defview message-input [input-options set-layout-size] (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 message-input [set-layout-size]
[input-message [:get-chat-input-text] [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] disable? [:get :disable-input]
active? [:chat :is-active]] active? [:chat :is-active]
[text-input (merge command? [:command?]
(plain-input-options (or disable? (not active?))) 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 {:placeholder-text-color :#c0c5c9
:auto-focus false :auto-focus (when command?
:blur-on-submit true (not (:fullscreen command)))
:blur-on-submit false
:multiline true :multiline true
:on-content-size-change #(let [size (-> (.-nativeEvent %) :on-content-size-change #(let [size (-> (.-nativeEvent %)
(.-contentSize) (.-contentSize)
@ -55,27 +79,16 @@
(dispatch [:set-chat-ui-props :show-emoji? false])) (dispatch [:set-chat-ui-props :show-emoji? false]))
:on-blur #(do (dispatch [:set :focused false]) :on-blur #(do (dispatch [:set :focused false])
(set-layout-size 0)) (set-layout-size 0))
:default-value (or input-message "")} :default-value (if command?
input-options)]) (or input-command "")
(or input-message ""))}
(defview command-input [input-options {:keys [fullscreen]} sending-disabled?] (when command?
[input-command [:get-chat-command-content] (get-options parameter type)))])
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)])
(defn plain-message-get-initial-state [_] (defn plain-message-get-initial-state [_]
{:height 0}) {:height 0})
(defn plain-message-input-view [_] (defn plain-message-input-view []
(let [command? (subscribe [:command?]) (let [command? (subscribe [:command?])
command (subscribe [:get-chat-command]) command (subscribe [:get-chat-command])
input-command (subscribe [:get-chat-command-content]) input-command (subscribe [:get-chat-command-content])
@ -93,15 +106,13 @@
(and (not @command?) (not @input-message))) (and (not @command?) (not @input-message)))
(set-layout-size 0))) (set-layout-size 0)))
:reagent-render :reagent-render
(fn [{:keys [input-options]}] (fn []
(let [{:keys [height]} (r/state component)] (let [{:keys [height]} (r/state component)]
[view st/input-container [view st/input-container
[view (st/input-view height) [view (st/input-view height)
[plain-message/commands-button height #(set-layout-size 0)] [plain-message/commands-button height #(set-layout-size 0)]
[view (st/message-input-container height) [view (st/message-input-container height)
(if @command? [message-input set-layout-size]]
[command-input input-options @command @sending-disabled?]
[message-input input-options set-layout-size])]
[plain-message/smile-button height] [plain-message/smile-button height]
(when (or (and @command? (not (str/blank? @input-command))) (when (or (and @command? (not (str/blank? @input-command)))
@valid-plain-message?) @valid-plain-message?)

View File

@ -12,25 +12,10 @@
(defn get-height [event] (defn get-height [event]
(.-height (.-layout (.-nativeEvent 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 [] (defview chat-message-input-view []
[margin [:input-margin] [margin [:input-margin]
command? [:command?] command? [:command?]
response-height [:response-height] response-height [:response-height]
parameter [:get-command-parameter]
type [:command-type]
suggestions [:get-suggestions] suggestions [:get-suggestions]
message-input-height [:get-message-input-view-height]] message-input-height [:get-message-input-view-height]]
(let [on-top? (or (and (seq suggestions) (not command?)) (let [on-top? (or (and (seq suggestions) (not command?))
@ -41,5 +26,4 @@
(let [height (get-height event)] (let [height (get-height event)]
(when (not= height message-input-height) (when (not= height message-input-height)
(dispatch [:set-message-input-view-height height]))))} (dispatch [:set-message-input-view-height height]))))}
[plain-message-input-view [plain-message-input-view]]))
(when command? (get-options parameter type))]]))

View File

@ -25,7 +25,8 @@
[status-im.utils.datetime :as dt] [status-im.utils.datetime :as dt]
[status-im.utils.name :refer [shortened-name]] [status-im.utils.name :refer [shortened-name]]
[status-im.utils.js-resources :as js-res] [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 [] (defn drag-icon []
[view st/drag-container [view st/drag-container

View File

@ -81,12 +81,7 @@
(reg-handler :suggestions-handler (reg-handler :suggestions-handler
[(after #(dispatch [:animate-show-response])) [(after #(dispatch [:animate-show-response]))
(after (print-error-message! "Error on param suggestions")) (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!))))]
suggestions-handler!) suggestions-handler!)
(reg-handler :suggestions-event! (u/side-effect! suggestions-events-handler!)) (reg-handler :suggestions-event! (u/side-effect! suggestions-events-handler!))