[#6042] [desktop] fix Caret position is changed when typing fast in input message field

This commit is contained in:
Roman Volosovskyi 2018-10-01 11:12:21 +03:00
parent c91e503b94
commit b6bb596a00
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
1 changed files with 13 additions and 9 deletions

View File

@ -189,6 +189,17 @@
:current-public-key current-public-key)]))]]
[connectivity/error-view]])))
(views/defview send-button [inp-ref]
(views/letsubs [{:keys [input-text]} [:get-current-chat]]
(let [empty? (= "" input-text)]
[react/touchable-highlight {:style styles/send-button
:on-press (fn []
(.clear @inp-ref)
(.focus @inp-ref)
(re-frame/dispatch [:chat.ui/send-current-message]))}
[react/view {:style (styles/send-icon empty?)}
[icons/icon :icons/arrow-left {:style (styles/send-icon-arrow empty?)}]]])))
(views/defview chat-text-input [chat-id input-text]
(views/letsubs [inp-ref (atom nil)]
{:should-component-update
@ -197,7 +208,7 @@
(not= old-chat-id new-chat-id))}
(let [component (reagent/current-component)
set-container-height-fn #(reagent/set-state component {:container-height %})
{:keys [container-height empty?] :or {empty? true}} (reagent/state component)]
{:keys [container-height]} (reagent/state component)]
[react/view {:style (styles/chat-box container-height)}
[react/text-input {:placeholder (i18n/label :t/type-a-message)
:auto-focus true
@ -220,15 +231,8 @@
:on-change (fn [e]
(let [native-event (.-nativeEvent e)
text (.-text native-event)]
(reagent/set-state component {:empty? (= "" text)})
(re-frame/dispatch [:chat.ui/set-chat-input-text text])))}]
[react/touchable-highlight {:style styles/send-button
:on-press (fn []
(.clear @inp-ref)
(.focus @inp-ref)
(re-frame/dispatch [:chat.ui/send-current-message]))}
[react/view {:style (styles/send-icon empty?)}
[icons/icon :icons/arrow-left {:style (styles/send-icon-arrow empty?)}]]]])))
[send-button inp-ref]])))
(views/defview chat-view []
(views/letsubs [{:keys [input-text chat-id] :as current-chat} [:get-current-chat]]