text-change optimisations (#971)

This commit is contained in:
alwx 2017-04-21 10:37:44 +03:00 committed by Roman Volosovskyi
parent 96dc348d7c
commit 735639776b
12 changed files with 50 additions and 46 deletions

View File

@ -47,9 +47,8 @@
(assoc db :layout-height height)))
(register-handler :set-chat-ui-props
(fn [{:keys [current-chat-id] :as db} [_ ui-element value chat-id]]
(let [chat-id (or chat-id current-chat-id)]
(assoc-in db [:chat-ui-props chat-id ui-element] value))))
(fn [{:keys [current-chat-id] :as db} [_ kvs]]
(update-in db [:chat-ui-props current-chat-id] merge kvs)))
(register-handler :toggle-chat-ui-props
(fn [{:keys [current-chat-id chat-ui-props] :as db} [_ ui-element chat-id]]
@ -59,9 +58,9 @@
(register-handler :show-message-details
(u/side-effect!
(fn [_ [_ details]]
(dispatch [:set-chat-ui-props :show-bottom-info? true])
(dispatch [:set-chat-ui-props :show-emoji? false])
(dispatch [:set-chat-ui-props :bottom-info details]))))
(dispatch [:set-chat-ui-props {:show-bottom-info? true
:show-emoji? false
:bottom-info details}]))))
(register-handler :load-more-messages
(fn [{:keys [current-chat-id loading-allowed] :as db} _]

View File

@ -45,9 +45,9 @@
(when-not sequential-params
(input-model/join-command-args prefill)))])
(dispatch [:set-chat-input-metadata metadata])
(dispatch [:set-chat-ui-props :show-suggestions? false])
(dispatch [:set-chat-ui-props :result-box nil])
(dispatch [:set-chat-ui-props :validation-messages nil])
(dispatch [:set-chat-ui-props {:show-suggestions? false
:result-box nil
:validation-messages nil}])
(dispatch [:load-chat-parameter-box command 0])
(if sequential-params
(js/setTimeout
@ -145,7 +145,7 @@
:address current-account-id}]
(dispatch [:set-chat-input-text nil chat-id])
(dispatch [:set-chat-input-metadata nil chat-id])
(dispatch [:set-chat-ui-props :sending-in-progress? false])
(dispatch [:set-chat-ui-props {:sending-in-progress? false}])
(cond
command-message
(dispatch [:check-commands-handlers! data])
@ -173,15 +173,15 @@
::proceed-validation-messages
(handlers/side-effect!
(fn [db [_ command chat-id {:keys [markup validationHandler parameters] :as errors} proceed-fn]]
(let [set-errors #(do (dispatch [:set-chat-ui-props :validation-messages %])
(dispatch [:set-chat-ui-props :sending-in-progress? false]))]
(let [set-errors #(do (dispatch [:set-chat-ui-props {:validation-messages %
:sending-in-progress? false}]))]
(cond
markup
(set-errors markup)
validationHandler
(do (dispatch [::execute-validation-handler validationHandler parameters set-errors proceed-fn])
(dispatch [:set-chat-ui-props :sending-in-progress? false]))
(dispatch [:set-chat-ui-props {:sending-in-progress? false}]))
:default
(proceed-fn))))))
@ -201,8 +201,8 @@
(do
(when fullscreen
(dispatch [:choose-predefined-expandable-height :result-box :max]))
(dispatch [:set-chat-ui-props :result-box on-send])
(dispatch [:set-chat-ui-props :sending-in-progress? false])
(dispatch [:set-chat-ui-props {:result-box on-send
:sending-in-progress? false}])
(react-comp/dismiss-keyboard!))
(dispatch [::request-command-data
{:command command
@ -241,7 +241,7 @@
:send-current-message
(handlers/side-effect!
(fn [{:keys [current-chat-id] :as db} [_ chat-id]]
(dispatch [:set-chat-ui-props :sending-in-progress? true])
(dispatch [:set-chat-ui-props {:sending-in-progress? true}])
(let [chat-id (or chat-id current-chat-id)
chat-command (input-model/selected-chat-command db chat-id)
seq-command? (get-in chat-command [:command :sequential-params])
@ -255,7 +255,7 @@
(dispatch [:proceed-command chat-command chat-id])
(dispatch [:clear-seq-arguments chat-id]))
(let [text (get-in db [:chats chat-id :input-text])]
(dispatch [:set-chat-ui-props :sending-in-progress? false])
(dispatch [:set-chat-ui-props {:sending-in-progress? false}])
(when-not (input-model/text-ends-with-space? text)
(dispatch [:set-chat-input-text (str text const/spacing-char)]))))
(dispatch [::send-message nil chat-id]))))))

View File

@ -62,7 +62,7 @@
:else
(dispatch [:prepare-command! chat-id params']))))
(dispatch [:set-chat-ui-props :sending-in-progress? false]))))
(dispatch [:set-chat-ui-props {:sending-in-progress? false}]))))
(register-handler :prepare-command!
(u/side-effect!
@ -78,7 +78,7 @@
(cu/check-author-direction db chat-id))]
(log/debug "Handler data: " request handler-data (dissoc params :commands :command-message))
(dispatch [:update-message-overhead! chat-id network-status])
(dispatch [:set-chat-ui-props :sending-in-progress? false])
(dispatch [:set-chat-ui-props {:sending-in-progress? false}])
(dispatch [::send-command! add-to-chat-id (assoc params :command command') hidden-params])
(when (cu/console? chat-id)
(dispatch [:console-respond-command params]))

View File

@ -90,11 +90,11 @@
(fn []
(if @show-actions
[touchable-highlight
{:on-press #(dispatch [:set-chat-ui-props :show-actions? false])}
{:on-press #(dispatch [:set-chat-ui-props {:show-actions? false}])}
[view st/action
[icon :up st/up-icon]]]
[touchable-highlight
{:on-press #(dispatch [:set-chat-ui-props :show-actions? true])}
{:on-press #(dispatch [:set-chat-ui-props {:show-actions? true}])}
[view st/action
[chat-icon]]]))))
@ -184,7 +184,7 @@
layout-height [:get :layout-height]
input-text [:chat :input-text]]
{:component-did-mount #(dispatch [:check-autorun])
:component-will-unmount #(dispatch [:set-chat-ui-props :show-emoji? false])}
:component-will-unmount #(dispatch [:set-chat-ui-props {:show-emoji? false}])}
[view {:style st/chat-view
:on-layout (fn [event]
(let [height (.. event -nativeEvent -layout -height)]

View File

@ -95,7 +95,7 @@
subtitle]
icon-name :icon}]
[touchable-highlight {:on-press (fn []
(dispatch [:set-chat-ui-props :show-actions? false])
(dispatch [:set-chat-ui-props {:show-actions? false}])
(when handler
(handler)))}
[view st/action-icon-row
@ -132,5 +132,5 @@
^{:key action} [action-view action]))]]))))
(defn actions-view []
[overlay {:on-click-outside #(dispatch [:set-chat-ui-props :show-actions? false])}
[overlay {:on-click-outside #(dispatch [:set-chat-ui-props {:show-actions? false}])}
[actions-list-view]])

View File

@ -78,7 +78,7 @@
:status message-status}]))
(into {}))
statuses (vals (merge participants user-statuses))]
[overlay {:on-click-outside #(dispatch [:set-chat-ui-props :show-bottom-info? false])}
[overlay {:on-click-outside #(dispatch [:set-chat-ui-props {:show-bottom-info? false}])}
[container (* st/item-height (count statuses))
[list-view {:dataSource (lw/to-datasource statuses)
:enableEmptySections true

View File

@ -41,7 +41,7 @@
[view style/commands-root
[view style/command-list-icon-container
[touchable-highlight {:on-press #(do (dispatch [:toggle-chat-ui-props :show-suggestions?])
(dispatch [:set-chat-ui-props :validation-messages nil])
(dispatch [:set-chat-ui-props {:validation-messages nil}])
(dispatch [:update-suggestions]))}
[view style/commands-list-icon
(if show-suggestions?
@ -65,12 +65,13 @@
input-focused? (subscribe [:chat-ui-props :input-focused?])]
(fn [{:keys [set-layout-height height]}]
[text-input
{:ref #(dispatch [:set-chat-ui-props :input-ref %])
{:ref #(when %
(dispatch [:set-chat-ui-props {:input-ref %}]))
:accessibility-label id/chat-message-input
:multiline true
:default-value (or @input-text "")
:editable (not @sending-in-progress?)
:on-blur #(do (dispatch [:set-chat-ui-props :input-focused? false])
:on-blur #(do (dispatch [:set-chat-ui-props {:input-focused? false}])
(set-layout-height 0))
:on-content-size-change (when-not @input-focused?
#(let [h (-> (.-nativeEvent %)
@ -82,18 +83,21 @@
(.-height))]
(set-layout-height h))
:on-change-text #(do (dispatch [:set-chat-input-text %])
(dispatch [:load-chat-parameter-box (:command @command)])
(when (not @command)
(dispatch [:set-chat-input-metadata nil])
(dispatch [:set-chat-ui-props :result-box nil]))
(dispatch [:set-chat-ui-props :validation-messages nil]))
(if @command
(do
(dispatch [:load-chat-parameter-box (:command @command)])
(dispatch [:set-chat-ui-props {:validation-messages nil}]))
(do
(dispatch [:set-chat-input-metadata nil])
(dispatch [:set-chat-ui-props {:result-box nil
:validation-messages nil}]))))
:on-selection-change #(let [s (-> (.-nativeEvent %)
(.-selection))]
(when (and (= (.-end s) (+ 2 (count (get-in @command [:command :name]))))
(get-in @command [:command :sequential-params]))
(dispatch [:chat-input-focus :seq-input-ref])))
:on-focus #(do (dispatch [:set-chat-ui-props :input-focused? true])
(dispatch [:set-chat-ui-props :show-emoji? false]))
:on-focus #(dispatch [:set-chat-ui-props {:input-focused? true
:show-emoji? false}])
:style (style/input-view height)
:placeholder-text-color style/color-input-helper-placeholder
:auto-capitalize :sentences}])))
@ -141,11 +145,11 @@
(fn [{:keys [command-width]}]
(when (get-in @command [:command :sequential-params])
(let [{:keys [placeholder hidden type]} (get-in @command [:command :params @arg-pos])]
[text-input (merge {:ref #(dispatch [:set-chat-ui-props :seq-input-ref %])
[text-input (merge {:ref #(dispatch [:set-chat-ui-props {:seq-input-ref %}])
:style (style/seq-input-text command-width)
:default-value (or @seq-arg-input-text "")
:on-change-text #(do (dispatch [:set-chat-seq-arg-input-text %])
(dispatch [:set-chat-ui-props :validation-messages nil]))
(dispatch [:set-chat-ui-props {:validation-messages nil}]))
:secure-text-entry hidden
:placeholder placeholder
:blur-on-submit false
@ -184,8 +188,8 @@
[touchable-highlight
{:on-press #(do (dispatch [:set-chat-input-text nil])
(dispatch [:set-chat-input-metadata nil])
(dispatch [:set-chat-ui-props :result-box nil])
(dispatch [:set-chat-ui-props :validation-messages nil])
(dispatch [:set-chat-ui-props {:result-box nil
:validation-messages nil}])
(dispatch [:clear-seq-arguments]))}
[view style/input-clear-container
[icon :close_gray style/input-clear-icon]]])]))})))
@ -252,7 +256,8 @@
:on-layout #(let [h (-> (.-nativeEvent %)
(.-layout)
(.-height))]
(dispatch [:set-chat-ui-props :input-height h]))}
(when (> h 0)
(dispatch [:set-chat-ui-props {:input-height h}])))}
[animated-view {:style (style/container container-anim-margin bottom-anim-margin)}
(when (str/blank? @input-text)
[commands-view])

View File

@ -20,7 +20,7 @@
:number-of-lines 1
:font :medium}
title]
[touchable-highlight {:on-press #(dispatch [:set-chat-ui-props :result-box nil])}
[touchable-highlight {:on-press #(dispatch [:set-chat-ui-props {:result-box nil}])}
[view style/header-close-container
[icon :close_light_gray style/header-close-icon]]]]])

View File

@ -16,7 +16,7 @@
(when-not loading
(dispatch [:set-command-argument [0 url]]))
(when (and dynamicTitle (not (str/blank? title)))
(dispatch [:set-chat-ui-props :result-box (assoc result-box :title title)])))))
(dispatch [:set-chat-ui-props {:result-box (assoc result-box :title title)}])))))
(defn web-view-error []
(r/as-element

View File

@ -21,7 +21,7 @@
(cond
handler-error
(when-let [markup (:markup handler-error)]
(dispatch [:set-chat-ui-props :validation-messages (cu/generate-hiccup markup)]))
(dispatch [:set-chat-ui-props {:validation-messages (cu/generate-hiccup markup)}]))
result
(let [command' (assoc command-message :handler-data returned)

View File

@ -77,7 +77,7 @@
[web3 {:keys [message-id to] :as pending-message}]
{:pre [(valid? :delivery/pending-message pending-message)]}
(debug :add-prepeared-pending-message!)
(let [message (select-keys pending-message [:from :to :topics :payload])
(let [message (select-keys pending-message [:from :to :topics :payload])
pending-message' (assoc pending-message :message message
:id message-id)]
(swap! messages assoc-in [web3 message-id to] pending-message')

View File

@ -205,10 +205,10 @@
(dispatch [::remove-pending-message message_id]))
(dispatch [:clear-selected-transaction])
(dispatch [::remove-transaction id])
(dispatch [:set-chat-ui-props :validation-messages error_message]))
(dispatch [:set-chat-ui-props {:validation-messages error_message}]))
:else
(dispatch [:set-chat-ui-props :validation-messages nil])))))
(dispatch [:set-chat-ui-props {:validation-messages nil}])))))
(register-handler :clear-selected-transaction
(fn [db _]