[FIX #3641] Modify chat input to retain text, parameter box on blur

chat: adds messages-focused chat prop to fine tune command interactions
This commit is contained in:
kwingram25 2018-03-22 18:09:15 -07:00 committed by Roman Volosovskyi
parent 31728d5493
commit 5297100c53
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
5 changed files with 30 additions and 17 deletions

View File

@ -51,6 +51,7 @@
(def check-box (get-class "CheckBox"))
(def touchable-highlight-class (get-class "TouchableHighlight"))
(def touchable-without-feedback-class (get-class "TouchableWithoutFeedback"))
(def touchable-opacity (get-class "TouchableOpacity"))
(def activity-indicator (get-class "ActivityIndicator"))
@ -114,6 +115,11 @@
(merge {:underlay-color :transparent} props)
content])
(defn touchable-without-feedback [props content]
[touchable-without-feedback-class
props
content])
(defn get-dimensions [name]
(js->clj (.get dimensions name) :keywordize-keys true))

View File

@ -89,13 +89,19 @@
[react/with-activity-indicator
{:style style/message-view-preview
:preview [react/view style/message-view-preview]}
[react/touchable-without-feedback
{:on-press (fn [_]
(re-frame/dispatch [:set-chat-ui-props {:messages-focused? true}])
(react/dismiss-keyboard!))}
[react/animated-view {:style (style/message-view-animated opacity)}
message-view]]))
message-view]]]))
(defview messages-view [group-chat]
(letsubs [messages [:get-current-chat-messages]
current-public-key [:get-current-public-key]
chat-id [:get-current-chat-id]]
chat-id [:get-current-chat-id]
current-public-key [:get-current-public-key]]
{:component-did-mount #(re-frame/dispatch [:set-chat-ui-props {:messages-focused? true
:input-focused? false}])}
(if (empty? messages)
[react/view style/empty-chat-container
[react/text {:style style/empty-chat-text}
@ -111,7 +117,7 @@
:inverted true
:onEndReached #(re-frame/dispatch [:load-more-messages])
:enableEmptySections true
:keyboardShouldPersistTaps (if platform/android? :always :handled)}])))
:keyboardShouldPersistTaps :handled}])))
(defview chat []
(letsubs [{:keys [group-chat public? input-text]} [:get-current-chat]

View File

@ -19,10 +19,11 @@
(defview expandable-view [{:keys [key]} & elements]
(letsubs [anim-value (animation/create-value 0)
input-height [:get-current-chat-ui-prop :input-height]
input-focused? [:get-current-chat-ui-prop :input-focused?]
messages-focused? [:get-current-chat-ui-prop :messages-focused?]
chat-input-margin [:chat-input-margin]
keyboard-height [:get :keyboard-height]
chat-layout-height [:get :layout-height]
input-focused? [:get-current-chat-ui-prop :input-focused?]]
chat-layout-height [:get :layout-height]]
(let [input-height (or input-height (+ input-style/padding-vertical
input-style/min-input-height
input-style/padding-vertical
@ -34,5 +35,5 @@
(into [react/scroll-view {:keyboard-should-persist-taps :always
:on-content-size-change #(expandable-view-on-update anim-value %2)
:bounces false}]
(when input-focused?
(when (or input-focused? (not messages-focused?))
elements))]])))

View File

@ -29,10 +29,9 @@
:default-value (or input-text "")
:editable true
:blur-on-submit false
:on-focus #(re-frame/dispatch [:set-chat-ui-props {:input-focused? true}])
:on-blur (fn []
(re-frame/dispatch [:set-chat-ui-props {:input-focused? false}])
(re-frame/dispatch [:set-chat-input-text ""]))
:on-focus #(re-frame/dispatch [:set-chat-ui-props {:input-focused? true
:messages-focused? false}])
:on-blur #(re-frame/dispatch [:set-chat-ui-props {:input-focused? false}])
:on-submit-editing (fn [_]
(if single-line-input?
(re-frame/dispatch [:send-current-message])

View File

@ -339,7 +339,8 @@
(defn chat-message [{:keys [outgoing group-chat current-public-key content-type content] :as message}]
[message-container message
[react/touchable-highlight {:on-press #(when platform/ios?
[react/touchable-highlight {:on-press (fn [_]
(re-frame/dispatch [:set-chat-ui-props {:messages-focused? true}])
(react/dismiss-keyboard!))
:on-long-press #(when (= content-type constants/text-content-type)
(list-selection/share content (i18n/label :t/message)))}