Skip to content

Commit

Permalink
multiline chat input
Browse files Browse the repository at this point in the history
  • Loading branch information
alwx committed Dec 22, 2016
1 parent 6002d53 commit a58ed1a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
25 changes: 18 additions & 7 deletions src/status_im/chat/views/message_input.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@

(defn plain-input-options [disable?]
{:style st-message/message-input
:on-change-text (when-not disable? plain-message/set-input-message)
:editable (not disable?)
:on-submit-editing plain-message/send})
:editable (not disable?)})

(defn on-press-commands-handler
[{:keys [suggestions-trigger]}]
Expand All @@ -40,23 +38,36 @@
(defview message-input [input-options set-layout-size]
[input-message [:get-chat-input-text]
disable? [:get :disable-input]
active? [:chat :is-active]]
active? [:chat :is-active]
input-ref (r/atom nil)
change-content-size? (r/atom true)]
[text-input (merge
(plain-input-options (or disable? (not active?)))
{:placeholder-text-color :#c0c5c9
:auto-focus false
:blur-on-submit true
:multiline true
:ref #(reset! input-ref %)
:on-content-size-change #(let [size (-> (.-nativeEvent %)
(.-contentSize)
(.-height))]
(set-layout-size size))
(when @change-content-size?
(set-layout-size size)))
:accessibility-label :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 "")}
:default-value (or input-message "")
:on-key-press #(when (= "Enter" (.-key (.-nativeEvent %)))
(reset! change-content-size? false))
:on-change-text #(when-not disable?
(if (str/includes? % "\n")
(do
(.clear @input-ref)
(plain-message/set-input-message "")
(plain-message/send)
(reset! change-content-size? true))
(plain-message/set-input-message %)))}
input-options)])

(defview command-input [input-options {:keys [fullscreen] :as command}]
Expand Down
5 changes: 4 additions & 1 deletion src/status_im/components/drawer/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
keyboard-height (subscribe [:get :keyboard-height])
placeholder (generate-gfy)
status-edit? (r/atom false)
status-text (r/atom nil)]
status-text (r/atom nil)
input-ref (r/atom nil)]
(fn []
(let [{:keys [name photo-path status]} @account
{new-name :name
Expand All @@ -81,6 +82,7 @@
[view st/status-container
(if @status-edit?
[text-input {:style st/status-input
:ref #(reset! input-ref %)
:editable true
:multiline true
:auto-focus true
Expand All @@ -96,6 +98,7 @@
(reset! status-text status)
(if (str/includes? % "\n")
(do
(.clear @input-ref)
(reset! status-edit? false)
(update-status status))
(dispatch [:set-in [:profile-edit :status] status])))}]
Expand Down

0 comments on commit a58ed1a

Please sign in to comment.