fix input

This commit is contained in:
Roman Volosovskyi 2016-06-20 20:31:14 +03:00
parent 5e7df10c76
commit d298a142f7
3 changed files with 29 additions and 36 deletions

View File

@ -259,6 +259,7 @@
[group-chat [:chat :group-chat] [group-chat [:chat :group-chat]
show-actions-atom [:show-actions] show-actions-atom [:show-actions]
command [:get-chat-command] command [:get-chat-command]
command? [:animations :command?]
to-msg-id [:get-chat-command-to-msg-id]] to-msg-id [:get-chat-command-to-msg-id]]
[view {:style st/chat-view [view {:style st/chat-view
:onLayout (fn [event] :onLayout (fn [event]
@ -269,8 +270,7 @@
[messages-view group-chat]] [messages-view group-chat]]
(when group-chat [typing-all]) (when group-chat [typing-all])
(cond (cond
(and command to-msg-id) [response-view] command? [response-view]
command [content-suggestions-view]
:else [suggestions-view]) :else [suggestions-view])
[chat-message-new] [chat-message-new]
(when show-actions-atom [actions-view])]) (when show-actions-atom [actions-view])])

View File

@ -39,48 +39,42 @@
(defview message-input [input-options validator] (defview message-input [input-options validator]
[input-message [:get-chat-input-text] [input-message [:get-chat-input-text]
command [:get-chat-command] command [:get-chat-command]
command? [:animations :command?]
to-msg-id [:get-chat-command-to-msg-id] to-msg-id [:get-chat-command-to-msg-id]
input-command [:get-chat-command-content] input-command [:get-chat-command-content]
staged-commands [:get-chat-staged-commands] staged-commands [:get-chat-staged-commands]
typing-command? [:typing-command?]] typing-command? [:typing-command?]]
(let [dismiss-keyboard (not (or command typing-command?)) (let [dismiss-keyboard (not (or command typing-command?))]
response? (and command to-msg-id) [text-input (merge {:style (if command?
message-input? (not command)] st-response/command-input
[text-input (merge {:style (cond st-message/message-input)
message-input? st-message/message-input :ref #(dispatch [:set-message-input %])
response? st-response/command-input
command st-command/command-input)
:ref (fn [input]
(dispatch [:set-message-input input]))
:autoFocus false :autoFocus false
:blurOnSubmit dismiss-keyboard :blurOnSubmit dismiss-keyboard
:onChangeText (fn [text] :onChangeText (if command?
((if message-input? command/set-input-message
plain-message/set-input-message plain-message/set-input-message)
command/set-input-message) :onSubmitEditing #(if command?
text)) (command/try-send input-command validator)
:onSubmitEditing #(if message-input?
(plain-message/try-send staged-commands (plain-message/try-send staged-commands
input-message input-message
dismiss-keyboard) dismiss-keyboard))}
(command/try-send input-command validator))} (when command?
(when command
{:accessibility-label :command-input}) {:accessibility-label :command-input})
input-options) input-options)
(if message-input? (if command?
input-message input-command
input-command)])) input-message)]))
(defview plain-message-input-view [{:keys [input-options validator]}] (defview plain-message-input-view [{:keys [input-options validator]}]
[input-message [:get-chat-input-text] [input-message [:get-chat-input-text]
command [:get-chat-command] command [:get-chat-command]
command? [:animations :command?]
to-msg-id [:get-chat-command-to-msg-id] to-msg-id [:get-chat-command-to-msg-id]
input-command [:get-chat-command-content] input-command [:get-chat-command-content]
staged-commands [:get-chat-staged-commands] staged-commands [:get-chat-staged-commands]
typing-command? [:typing-command?]] typing-command? [:typing-command?]]
(let [dismiss-keyboard (not (or command typing-command?)) (let [dismiss-keyboard (not (or command typing-command?))]
response? (and command to-msg-id)
message-input? (not command)]
[view st/input-container [view st/input-container
[view st/input-view [view st/input-view
[plain-message/commands-button] [plain-message/commands-button]
@ -88,14 +82,12 @@
[message-input input-options validator]] [message-input input-options validator]]
;; TODO emoticons: not implemented ;; TODO emoticons: not implemented
[plain-message/smile-button] [plain-message/smile-button]
(if message-input? (if-not command?
(when (plain-message/message-valid? staged-commands input-message) (when (plain-message/message-valid? staged-commands input-message)
[send-button {:on-press #(plain-message/try-send staged-commands [send-button {:on-press #(plain-message/try-send staged-commands
input-message input-message
dismiss-keyboard) dismiss-keyboard)
:accessibility-label :send-message}]) :accessibility-label :send-message}])
(if (command/valid? input-command validator) (when (command/valid? input-command validator)
[send-button {:on-press command/send-command [send-button {:on-press command/send-command
:accessibility-label :stage-command}] :accessibility-label :stage-command}]))]]))
(when-not response?
[command/cancel-button])))]]))

View File

@ -16,9 +16,11 @@
(for [command staged-commands] (for [command staged-commands]
^{:key command} [staged-command-view command])]) ^{:key command} [staged-command-view command])])
(defn show-input [command] (defview show-input []
[command [:get-chat-command]
command? [:animations :command?]]
[plain-message-input-view [plain-message-input-view
(when command (when command?
(case (:command command) (case (:command command)
:phone {:input-options {:keyboardType :phone-pad} :phone {:input-options {:keyboardType :phone-pad}
:validator valid-mobile-number?} :validator valid-mobile-number?}
@ -29,9 +31,8 @@
(throw (js/Error. "Uknown command type"))))]) (throw (js/Error. "Uknown command type"))))])
(defview chat-message-new [] (defview chat-message-new []
[command [:get-chat-command] [staged-commands [:get-chat-staged-commands]]
staged-commands [:get-chat-staged-commands]]
[view st/new-message-container [view st/new-message-container
(when (and staged-commands (pos? (count staged-commands))) (when (and staged-commands (pos? (count staged-commands)))
[staged-commands-view staged-commands]) [staged-commands-view staged-commands])
[show-input command]]) [show-input]])