From 991d909b972fdc4f4080e4983be24d7eb52349eb Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 20 Jun 2016 01:20:48 +0300 Subject: [PATCH 01/12] another attempt Former-commit-id: 5e7df10c76afdd4d0a83121c119a0d6b1432c06b --- src/status_im/chat/handlers.cljs | 8 +- src/status_im/chat/handlers/animation.cljs | 65 +++++------ src/status_im/chat/styles/message_input.cljs | 5 +- src/status_im/chat/styles/plain_message.cljs | 4 +- src/status_im/chat/styles/response.cljs | 1 - src/status_im/chat/views/command.cljs | 6 +- src/status_im/chat/views/message_input.cljs | 108 +++++++------------ src/status_im/chat/views/plain_message.cljs | 100 +++++++++-------- src/status_im/chat/views/response.cljs | 80 +++++++------- src/status_im/components/animation.cljs | 3 + src/status_im/constants.cljs | 2 +- src/status_im/db.cljs | 7 +- 12 files changed, 171 insertions(+), 218 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 9ec8b78858..05f1bef3a7 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -48,9 +48,7 @@ (register-handler :start-cancel-command (u/side-effect! (fn [db _] - (if (commands/get-chat-command-to-msg-id db) - (dispatch [:animate-cancel-command]) - (dispatch [:cancel-command]))))) + (dispatch [:animate-cancel-command])))) (defn animate-set-chat-command-content [db _] (when (commands/get-chat-command-to-msg-id db) @@ -78,7 +76,9 @@ command-info {:command command :content content :handler (:handler command)}] - (commands/stage-command db command-info)))) + (-> db + (assoc-in [:chats current-chat-id :command-input :command] nil) + (commands/stage-command command-info))))) (register-handler :set-message-input [] (fn [db [_ input]] diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index 2859261ab3..f296ea73d8 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -15,20 +15,12 @@ ([name middleware handler] (register-handler name [(path :animations) middleware] handler))) -(animation-handler :finish-animate-cancel-command - (fn [db _] - (assoc db :commands-input-is-switching? false))) - (animation-handler :animate-cancel-command (fn [db _] - (if-not (:commands-input-is-switching? db) - (assoc db - :commands-input-is-switching? true - :message-input-buttons-scale 1 - :message-input-offset 0 - :to-response-height zero-height - :messages-offset 0) - db))) + (assoc db + :command? false + :to-response-height zero-height + :messages-offset 0))) (animation-handler :finish-animate-response-resize (fn [db _] @@ -58,18 +50,12 @@ (defn update-response-height [db] (assoc-in db [:animations :to-response-height] (get-response-height db))) -(animation-handler :finish-show-response - (fn [db _] - (assoc db :commands-input-is-switching? false))) - (register-handler :animate-show-response (after #(dispatch [:animate-response-resize])) (fn [db _] (-> db - (assoc-in [:animations :commands-input-is-switching?] true) (assoc-in [:animations :response-height-current] zero-height) - (assoc-in [:animations :message-input-buttons-scale] 0.1) - (assoc-in [:animations :message-input-offset] -40) + (assoc-in [:animations :command?] true) (assoc-in [:animations :messages-offset] request-info-height) (update-response-height)))) @@ -91,21 +77,26 @@ :response-resize? false)))) (register-handler :fix-response-height - (fn [db _] - (if (and (commands/get-chat-command-to-msg-id db) - (not (get-in db [:animations :commands-input-is-switching?]))) - (let [current (get-in db [:animations :response-height-current]) - normal-height response-height-normal - command (commands/get-chat-command db) - text (commands/get-chat-command-content db) - suggestions (get-content-suggestions command text) - max-height (get-in db [:animations :response-height-max]) - delta (/ normal-height 2) - new-fixed (cond - (or (<= current (+ zero-height delta)) - (empty? suggestions)) (+ zero-height request-info-height) - (<= current (+ zero-height normal-height delta)) (get-response-height db) - :else max-height)] - (dispatch [:animate-response-resize]) - (assoc-in db [:animations :to-response-height] new-fixed)) - db))) + (fn [db [_ dy vy current]] + (let [max-height (get-in db [:animations :response-height-max]) + ;; todo magic value + middle 270 + moving-down? (pos? vy) + moving-up? (not moving-down?) + under-middle-position? (<= current middle) + over-middle-position? (not under-middle-position?) + min-height (+ zero-height request-info-height) + new-fixed (cond (and under-middle-position? moving-down?) + min-height + + (and under-middle-position? moving-up?) + middle + + (and over-middle-position? moving-down?) + middle + + (and over-middle-position? moving-up?) + max-height)] + (-> db + (assoc-in [:animations :to-response-height] new-fixed) + (update-in [:animations :response-height-changed] inc))))) diff --git a/src/status_im/chat/styles/message_input.cljs b/src/status_im/chat/styles/message_input.cljs index 9cbcc4e27f..ccde0a7994 100644 --- a/src/status_im/chat/styles/message_input.cljs +++ b/src/status_im/chat/styles/message_input.cljs @@ -4,10 +4,9 @@ (def input-height 56) -(defn message-input-container [offset] +(def message-input-container {:flex 1 - :transform [{:translateX offset}] - :marginRight offset}) + :marginRight 0}) (def input-container {:flexDirection :column}) diff --git a/src/status_im/chat/styles/plain_message.cljs b/src/status_im/chat/styles/plain_message.cljs index d52ae4d257..b85dea9a97 100644 --- a/src/status_im/chat/styles/plain_message.cljs +++ b/src/status_im/chat/styles/plain_message.cljs @@ -2,8 +2,8 @@ (:require [status-im.components.styles :refer [font text2-color]])) -(def message-input-button-touchable - {:width 56 +(defn message-input-button-touchable [w] + {:width w :height 56 :alignItems :center :justifyContent :center}) diff --git a/src/status_im/chat/styles/response.cljs b/src/status_im/chat/styles/response.cljs index 029ca2ed86..918bd28eec 100644 --- a/src/status_im/chat/styles/response.cljs +++ b/src/status_im/chat/styles/response.cljs @@ -87,7 +87,6 @@ (def command-input {:flex 1 - :marginLeft 56 :marginRight 16 :marginTop -2 :padding 0 diff --git a/src/status_im/chat/views/command.cljs b/src/status_im/chat/views/command.cljs index 582dacfa49..51b9bd8fd7 100644 --- a/src/status_im/chat/views/command.cljs +++ b/src/status_im/chat/views/command.cljs @@ -31,9 +31,7 @@ [view (st/command-text-container command) [text {:style st/command-text} (:text command)]]) -(defview cancel-button [] - [commands-input-is-switching? [:animations :commands-input-is-switching?]] - [touchable-highlight {:disabled commands-input-is-switching? - :on-press cancel-command-input} +(defn cancel-button [] + [touchable-highlight {:on-press cancel-command-input} [view st/cancel-container [icon :close-gray st/cancel-icon]]]) diff --git a/src/status_im/chat/views/message_input.cljs b/src/status_im/chat/views/message_input.cljs index 4c26e15eb8..d3bf3eccc8 100644 --- a/src/status_im/chat/views/message_input.cljs +++ b/src/status_im/chat/views/message_input.cljs @@ -18,10 +18,8 @@ [status-im.chat.styles.response :as st-response] [status-im.constants :refer [response-input-hiding-duration]])) -(defview send-button [{:keys [on-press accessibility-label]}] - [commands-input-is-switching? [:animations :commands-input-is-switching?]] - [touchable-highlight {:disabled commands-input-is-switching? - :on-press on-press +(defn send-button [{:keys [on-press accessibility-label]}] + [touchable-highlight {:on-press on-press :accessibility-label accessibility-label} [view st/send-container [icon :send st/send-icon]]]) @@ -36,61 +34,42 @@ (dispatch [:set-animation ::message-input-offset-current to-value]))))))) (defn message-input-container [input] - (let [to-message-input-offset (subscribe [:animations :message-input-offset]) - cur-message-input-offset (subscribe [:animations ::message-input-offset-current]) - message-input-offset (anim/create-value (or @cur-message-input-offset 0)) - context {:to-value to-message-input-offset - :val message-input-offset} - on-update (animation-logic context)] - (r/create-class - {:component-did-mount - on-update - :component-did-update - on-update - :reagent-render - (fn [input] - @to-message-input-offset - [animated-view {:style (st/message-input-container message-input-offset)} - input])}))) + [view st/message-input-container input]) (defview message-input [input-options validator] - [input-message [:get-chat-input-text] - command [:get-chat-command] - to-msg-id [:get-chat-command-to-msg-id] - input-command [:get-chat-command-content] - staged-commands [:get-chat-staged-commands] - typing-command? [:typing-command?] - commands-input-is-switching? [:animations :commands-input-is-switching?]] - (let [dismiss-keyboard (not (or command typing-command?)) - response? (and command to-msg-id) - message-input? (or (not command) commands-input-is-switching?) - animation? commands-input-is-switching?] - [text-input (merge {:style (cond - message-input? st-message/message-input - response? st-response/command-input - command st-command/command-input) - :ref (fn [input] - (dispatch [:set-message-input input])) - :autoFocus false - :blurOnSubmit dismiss-keyboard - :onChangeText (fn [text] - (when-not animation? - ((if message-input? - plain-message/set-input-message - command/set-input-message) - text))) - :onSubmitEditing #(when-not animation? - (if message-input? - (plain-message/try-send staged-commands - input-message - dismiss-keyboard) - (command/try-send input-command validator)))} - (when command - {:accessibility-label :command-input}) - input-options) - (if message-input? - input-message - input-command)])) + [input-message [:get-chat-input-text] + command [:get-chat-command] + to-msg-id [:get-chat-command-to-msg-id] + input-command [:get-chat-command-content] + staged-commands [:get-chat-staged-commands] + typing-command? [:typing-command?]] + (let [dismiss-keyboard (not (or command typing-command?)) + response? (and command to-msg-id) + message-input? (not command)] + [text-input (merge {:style (cond + message-input? st-message/message-input + response? st-response/command-input + command st-command/command-input) + :ref (fn [input] + (dispatch [:set-message-input input])) + :autoFocus false + :blurOnSubmit dismiss-keyboard + :onChangeText (fn [text] + ((if message-input? + plain-message/set-input-message + command/set-input-message) + text)) + :onSubmitEditing #(if message-input? + (plain-message/try-send staged-commands + input-message + dismiss-keyboard) + (command/try-send input-command validator))} + (when command + {:accessibility-label :command-input}) + input-options) + (if message-input? + input-message + input-command)])) (defview plain-message-input-view [{:keys [input-options validator]}] [input-message [:get-chat-input-text] @@ -98,22 +77,17 @@ to-msg-id [:get-chat-command-to-msg-id] input-command [:get-chat-command-content] staged-commands [:get-chat-staged-commands] - typing-command? [:typing-command?] - commands-input-is-switching? [:animations :commands-input-is-switching?]] + typing-command? [:typing-command?]] (let [dismiss-keyboard (not (or command typing-command?)) - response? (and command to-msg-id) - message-input? (or (not command) commands-input-is-switching?)] + response? (and command to-msg-id) + message-input? (not command)] [view st/input-container [view st/input-view - (if message-input? - [plain-message/commands-button] - (when (and command (not response?)) - [command/command-icon command response?])) + [plain-message/commands-button] [message-input-container [message-input input-options validator]] ;; TODO emoticons: not implemented - (when message-input? - [plain-message/smile-button]) + [plain-message/smile-button] (if message-input? (when (plain-message/message-valid? staged-commands input-message) [send-button {:on-press #(plain-message/try-send staged-commands diff --git a/src/status_im/chat/views/plain_message.cljs b/src/status_im/chat/views/plain_message.cljs index 7c637ebbd0..b7ecef4e2c 100644 --- a/src/status_im/chat/views/plain_message.cljs +++ b/src/status_im/chat/views/plain_message.cljs @@ -33,39 +33,29 @@ (.clear message-input) (.focus message-input))) -(defn commands-button-animation-callback [message-input] - (fn [arg to-value] - (when (.-finished arg) - (dispatch [:set-animation ::message-input-buttons-scale-current to-value]) - (when (<= to-value 0.1) - (dispatch [:finish-show-response]) - (prepare-message-input @message-input))))) - -(defn button-animation-logic [{:keys [to-value val callback]}] +(defn button-animation-logic [{:keys [command? val]}] (fn [_] - (let [to-scale @to-value - minimum 0.1 - scale (cond (< 1 to-scale) 1 - (< to-scale minimum) minimum - :else to-scale)] - (anim/start (anim/timing val {:toValue scale - :duration response-input-hiding-duration}) - (when callback - (fn [arg] - (callback arg to-scale))))))) + (let [to-scale (if @command? 0 1)] + (anim/start (anim/spring val {:toValue to-scale}))))) + +(defn list-container [min] + (fn [{:keys [command? width]}] + (let [n-width (if @command? min 56) + delay (if @command? 100 0)] + (anim/start (anim/timing width {:toValue n-width + :duration response-input-hiding-duration + :delay delay}))))) (defn commands-button [] - (let [typing-command? (subscribe [:typing-command?]) - message-input (subscribe [:get :message-input]) - animation? (subscribe [:animations :commands-input-is-switching?]) - to-scale (subscribe [:animations :message-input-buttons-scale]) - cur-scale (subscribe [:animations ::message-input-buttons-scale-current]) - buttons-scale (anim/create-value (or @cur-scale 1)) - anim-callback (commands-button-animation-callback message-input) - context {:to-value to-scale - :val buttons-scale - :callback anim-callback} - on-update (button-animation-logic context)] + (let [command? (subscribe [:animations :command?]) + buttons-scale (anim/create-value (if @command? 1 0)) + container-width (anim/create-value (if @command? 20 56)) + context {:command? command? + :val buttons-scale + :width container-width} + on-update (fn [_] + ((button-animation-logic context)) + ((list-container 20) context))] (r/create-class {:component-did-mount on-update @@ -73,24 +63,30 @@ on-update :reagent-render (fn [] - (let [typing-command? @typing-command?] - @to-scale - [touchable-highlight {:disabled @animation? - :on-press #(dispatch [:switch-command-suggestions]) - :style st/message-input-button-touchable} - [animated-view {:style (st/message-input-button buttons-scale)} - (if typing-command? - [icon :close-gray st/close-icon] - [icon :list st/list-icon])]]))}))) + [touchable-highlight {:on-press #(dispatch [:switch-command-suggestions]) + :disabled @command?} + [animated-view {:style (st/message-input-button-touchable + container-width)} + [animated-view {:style (st/message-input-button buttons-scale)} + [icon :list st/list-icon]]]])}))) + +(defn smile-animation-logic [{:keys [command? val width]}] + (fn [_] + (let [to-scale (if @command? 0 1)] + (when-not @command? (anim/set-value width 56)) + (anim/start (anim/spring val {:toValue to-scale}) + (fn [] + (when @command? + (anim/set-value width 0.1))))))) (defn smile-button [] - (let [animation? (subscribe [:animations :commands-input-is-switching?]) - to-scale (subscribe [:animations :message-input-buttons-scale]) - cur-scale (subscribe [:animations ::message-input-buttons-scale-current]) - buttons-scale (anim/create-value (or @cur-scale 1)) - context {:to-value to-scale - :val buttons-scale} - on-update (button-animation-logic context)] + (let [command? (subscribe [:animations :command?]) + buttons-scale (anim/create-value (if @command? 1 0)) + container-width (anim/create-value (if @command? 0.1 56)) + context {:command? command? + :val buttons-scale + :width container-width} + on-update (smile-animation-logic context)] (r/create-class {:component-did-mount on-update @@ -98,11 +94,11 @@ on-update :reagent-render (fn [] - @to-scale - [touchable-highlight {:disabled @animation? - :on-press (fn [] + [touchable-highlight {:on-press (fn [] ;; TODO emoticons: not implemented ) - :style st/message-input-button-touchable} - [animated-view {:style (st/message-input-button buttons-scale)} - [icon :smile st/smile-icon]]])}))) + :disabled @command?} + [animated-view {:style (st/message-input-button-touchable + container-width)} + [animated-view {:style (st/message-input-button buttons-scale)} + [icon :smile st/smile-icon]]]])}))) diff --git a/src/status_im/chat/views/response.cljs b/src/status_im/chat/views/response.cljs index 6f745b5844..7ff986e7a8 100644 --- a/src/status_im/chat/views/response.cljs +++ b/src/status_im/chat/views/response.cljs @@ -14,7 +14,8 @@ [status-im.chat.views.response-suggestions :refer [response-suggestions-view]] [status-im.chat.styles.response :as st] [status-im.chat.styles.message-input :refer [input-height]] - [status-im.components.animation :as anim])) + [status-im.components.animation :as anim] + [status-im.components.react :as react])) (defn drag-icon [] [view st/drag-container @@ -33,17 +34,25 @@ ;; TODO stub data: request message info "By ???, MMM 1st at HH:mm"]]) -(defn create-response-pan-responder [] +(defn create-response-pan-responder [response-height] (drag/create-pan-responder - {:on-move (fn [e gesture] - (dispatch [:on-drag-response (.-dy gesture)])) - :on-release (fn [e gesture] - (dispatch [:fix-response-height]))})) + {:on-move (fn [_ gesture] + (when (> (Math/abs (.-dy gesture)) 10) + (let [to-value (- (:height (react/get-dimensions "window")) + (.-moveY gesture))] + (anim/start + (anim/spring response-height {:toValue to-value}))))) + :on-release (fn [_ gesture] + (when (> (Math/abs (.-dy gesture)) 10) + (dispatch [:fix-response-height + (.-dy gesture) + (.-vy gesture) + (.-_value response-height)])))})) -(defn request-info [] - (let [pan-responder (create-response-pan-responder) - command (subscribe [:get-chat-command])] - (fn [] +(defn request-info [response-height] + (let [pan-responder (create-response-pan-responder response-height) + command (subscribe [:get-chat-command])] + (fn [response-height] [view (merge (drag/pan-handlers pan-responder) {:style (st/request-info (:color @command))}) [drag-icon] @@ -54,46 +63,33 @@ [view st/cancel-container [icon :close-white st/cancel-icon]]]]]))) -(defn container-animation-logic [{:keys [animation? to-value current-value val]}] +(defn container-animation-logic [{:keys [to-value val]}] (fn [_] - (if @animation? - (let [to-value @to-value] - (anim/start (anim/spring val {:toValue to-value}) - (fn [arg] - (when (.-finished arg) - (dispatch [:set-animation :response-height-current to-value]) - (dispatch [:finish-animate-response-resize]) - (when (= to-value input-height) - (dispatch [:finish-animate-cancel-command]) - (dispatch [:cancel-command])))))) - (anim/set-value val @current-value)))) + (let [to-value @to-value] + (anim/start (anim/spring val {:toValue to-value}))))) -(defn container [& children] - (let [commands-input-is-switching? (subscribe [:animations :commands-input-is-switching?]) - response-resize? (subscribe [:animations :response-resize?]) - to-response-height (subscribe [:animations :to-response-height]) - cur-response-height (subscribe [:animations :response-height-current]) - response-height (anim/create-value (or @cur-response-height 0)) - context {:animation? (reaction (or @commands-input-is-switching? @response-resize?)) - :to-value to-response-height - :current-value cur-response-height - :val response-height} - on-update (container-animation-logic context)] +(defn container [response-height & children] + (let [;; todo to-response-height, cur-response-height must be specific + ;; for each chat + to-response-height (subscribe [:animations :to-response-height]) + changed (subscribe [:animations :response-height-changed]) + context {:to-value to-response-height + :val response-height} + on-update (container-animation-logic context)] (r/create-class {:component-did-mount on-update :component-did-update on-update :reagent-render - (fn [& children] - @to-response-height - (into [animated-view {:style (st/response-view (if (or @commands-input-is-switching? @response-resize?) - response-height - (or @cur-response-height 0)))}] + (fn [response-height & children] + @to-response-height @changed + (into [animated-view {:style (st/response-view response-height)}] children))}))) (defn response-view [] - [container - [request-info] - [response-suggestions-view] - [view st/input-placeholder]]) + (let [response-height (anim/create-value 0)] + [container response-height + [request-info response-height] + [response-suggestions-view] + [view st/input-placeholder]])) diff --git a/src/status_im/components/animation.cljs b/src/status_im/components/animation.cljs index a945d44f4c..74d3cb3f78 100644 --- a/src/status_im/components/animation.cljs +++ b/src/status_im/components/animation.cljs @@ -11,6 +11,9 @@ (defn spring [anim-value config] (.spring animated anim-value (clj->js config))) +(defn decay [anim-value config] + (.decay animated anim-value (clj->js config))) + (defn anim-sequence [animations] (.sequence animated (clj->js animations))) diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index 556f9b7898..7faee32d1b 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -13,5 +13,5 @@ (def max-chat-name-length 20) -(def response-input-hiding-duration 300) +(def response-input-hiding-duration 100) (def response-suggesstion-resize-duration 100) diff --git a/src/status_im/db.cljs b/src/status_im/db.cljs index 2b3ad6f88f..e118920433 100644 --- a/src/status_im/db.cljs +++ b/src/status_im/db.cljs @@ -37,13 +37,10 @@ :whisper-identity "" :phone-number ""} :disable-group-creation false - :animations {;; mutable data - :to-response-height nil + :animations {:to-response-height nil :response-height-current nil - :message-input-offset 0 - :message-input-buttons-scale 1 + :command? false :messages-offset 0 - :commands-input-is-switching? false :response-resize? false}}) (def protocol-initialized-path [:protocol-initialized]) From 02f264251f858638546bbbf89db7b646eb227431 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 20 Jun 2016 20:31:14 +0300 Subject: [PATCH 02/12] fix input Former-commit-id: d298a142f7ed7f1376d7ab33d3fd91c6ea200752 --- src/status_im/chat/screen.cljs | 4 +- src/status_im/chat/views/message_input.cljs | 50 +++++++++------------ src/status_im/chat/views/new_message.cljs | 11 ++--- 3 files changed, 29 insertions(+), 36 deletions(-) diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index feb88de74e..2c04ab4859 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -259,6 +259,7 @@ [group-chat [:chat :group-chat] show-actions-atom [:show-actions] command [:get-chat-command] + command? [:animations :command?] to-msg-id [:get-chat-command-to-msg-id]] [view {:style st/chat-view :onLayout (fn [event] @@ -269,8 +270,7 @@ [messages-view group-chat]] (when group-chat [typing-all]) (cond - (and command to-msg-id) [response-view] - command [content-suggestions-view] + command? [response-view] :else [suggestions-view]) [chat-message-new] (when show-actions-atom [actions-view])]) diff --git a/src/status_im/chat/views/message_input.cljs b/src/status_im/chat/views/message_input.cljs index d3bf3eccc8..3dc34d8e1a 100644 --- a/src/status_im/chat/views/message_input.cljs +++ b/src/status_im/chat/views/message_input.cljs @@ -39,48 +39,42 @@ (defview message-input [input-options validator] [input-message [:get-chat-input-text] command [:get-chat-command] + command? [:animations :command?] to-msg-id [:get-chat-command-to-msg-id] input-command [:get-chat-command-content] staged-commands [:get-chat-staged-commands] typing-command? [:typing-command?]] - (let [dismiss-keyboard (not (or command typing-command?)) - response? (and command to-msg-id) - message-input? (not command)] - [text-input (merge {:style (cond - message-input? st-message/message-input - response? st-response/command-input - command st-command/command-input) - :ref (fn [input] - (dispatch [:set-message-input input])) + (let [dismiss-keyboard (not (or command typing-command?))] + [text-input (merge {:style (if command? + st-response/command-input + st-message/message-input) + :ref #(dispatch [:set-message-input %]) :autoFocus false :blurOnSubmit dismiss-keyboard - :onChangeText (fn [text] - ((if message-input? - plain-message/set-input-message - command/set-input-message) - text)) - :onSubmitEditing #(if message-input? + :onChangeText (if command? + command/set-input-message + plain-message/set-input-message) + :onSubmitEditing #(if command? + (command/try-send input-command validator) (plain-message/try-send staged-commands input-message - dismiss-keyboard) - (command/try-send input-command validator))} - (when command + dismiss-keyboard))} + (when command? {:accessibility-label :command-input}) input-options) - (if message-input? - input-message - input-command)])) + (if command? + input-command + input-message)])) (defview plain-message-input-view [{:keys [input-options validator]}] [input-message [:get-chat-input-text] command [:get-chat-command] + command? [:animations :command?] to-msg-id [:get-chat-command-to-msg-id] input-command [:get-chat-command-content] staged-commands [:get-chat-staged-commands] typing-command? [:typing-command?]] - (let [dismiss-keyboard (not (or command typing-command?)) - response? (and command to-msg-id) - message-input? (not command)] + (let [dismiss-keyboard (not (or command typing-command?))] [view st/input-container [view st/input-view [plain-message/commands-button] @@ -88,14 +82,12 @@ [message-input input-options validator]] ;; TODO emoticons: not implemented [plain-message/smile-button] - (if message-input? + (if-not command? (when (plain-message/message-valid? staged-commands input-message) [send-button {:on-press #(plain-message/try-send staged-commands input-message dismiss-keyboard) :accessibility-label :send-message}]) - (if (command/valid? input-command validator) + (when (command/valid? input-command validator) [send-button {:on-press command/send-command - :accessibility-label :stage-command}] - (when-not response? - [command/cancel-button])))]])) + :accessibility-label :stage-command}]))]])) diff --git a/src/status_im/chat/views/new_message.cljs b/src/status_im/chat/views/new_message.cljs index 3a330d0a0b..e8e53d2681 100644 --- a/src/status_im/chat/views/new_message.cljs +++ b/src/status_im/chat/views/new_message.cljs @@ -16,9 +16,11 @@ (for [command staged-commands] ^{:key command} [staged-command-view command])]) -(defn show-input [command] +(defview show-input [] + [command [:get-chat-command] + command? [:animations :command?]] [plain-message-input-view - (when command + (when command? (case (:command command) :phone {:input-options {:keyboardType :phone-pad} :validator valid-mobile-number?} @@ -29,9 +31,8 @@ (throw (js/Error. "Uknown command type"))))]) (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 (when (and staged-commands (pos? (count staged-commands))) [staged-commands-view staged-commands]) - [show-input command]]) + [show-input]]) From 9e72e52737b147819acd2b99b9bdfe23478ee9f9 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 20 Jun 2016 21:15:05 +0300 Subject: [PATCH 03/12] some refactoring Former-commit-id: 6299e7d686a38c8bc30f1c13bcdeffeace3bef51 --- src/status_im/chat/subs.cljs | 18 ++++- src/status_im/chat/views/message_input.cljs | 90 +++++++++------------ src/status_im/chat/views/plain_message.cljs | 13 +-- 3 files changed, 53 insertions(+), 68 deletions(-) diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index 9b11d29fd0..4486741df5 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -1,13 +1,15 @@ (ns status-im.chat.subs (:require-macros [reagent.ratom :refer [reaction]]) - (:require [re-frame.core :refer [register-sub dispatch]] + (:require [re-frame.core :refer [register-sub dispatch subscribe]] [status-im.db :as db] ;todo handlers in subs?... [status-im.chat.suggestions :refer [get-suggestions typing-command?]] [status-im.models.commands :as commands] [status-im.constants :refer [response-suggesstion-resize-duration]] - [status-im.handlers.content-suggestions :refer [get-content-suggestions]])) + [status-im.handlers.content-suggestions :refer [get-content-suggestions]] + [status-im.chat.views.plain-message :as plain-message] + [status-im.chat.views.command :as command])) (register-sub :chat-properties (fn [db [_ properties]] @@ -63,6 +65,18 @@ (get-in @db) (reaction)))) +(register-sub :valid-plain-message? + (fn [_ _] + (let [input-message (subscribe [:get-chat-input-text]) + staged-commands (subscribe [:get-chat-staged-commands])] + (reaction + (plain-message/message-valid? @staged-commands @input-message))))) + +(register-sub :valid-command? + (fn [_ [_ validator]] + (let [input (subscribe [:get-chat-command-content])] + (reaction (command/valid? @input validator))))) + (register-sub :get-chat-command (fn [db _] (reaction (commands/get-chat-command @db)))) diff --git a/src/status_im/chat/views/message_input.cljs b/src/status_im/chat/views/message_input.cljs index 3dc34d8e1a..67310f8a77 100644 --- a/src/status_im/chat/views/message_input.cljs +++ b/src/status_im/chat/views/message_input.cljs @@ -11,10 +11,8 @@ [status-im.components.animation :as anim] [status-im.chat.views.plain-message :as plain-message] [status-im.chat.views.command :as command] - [status-im.chat.views.response :as response] [status-im.chat.styles.message-input :as st] [status-im.chat.styles.plain-message :as st-message] - [status-im.chat.styles.input :as st-command] [status-im.chat.styles.response :as st-response] [status-im.constants :refer [response-input-hiding-duration]])) @@ -36,58 +34,42 @@ (defn message-input-container [input] [view st/message-input-container input]) -(defview message-input [input-options validator] - [input-message [:get-chat-input-text] - command [:get-chat-command] - command? [:animations :command?] - to-msg-id [:get-chat-command-to-msg-id] - input-command [:get-chat-command-content] - staged-commands [:get-chat-staged-commands] - typing-command? [:typing-command?]] - (let [dismiss-keyboard (not (or command typing-command?))] - [text-input (merge {:style (if command? - st-response/command-input - st-message/message-input) - :ref #(dispatch [:set-message-input %]) - :autoFocus false - :blurOnSubmit dismiss-keyboard - :onChangeText (if command? - command/set-input-message - plain-message/set-input-message) - :onSubmitEditing #(if command? - (command/try-send input-command validator) - (plain-message/try-send staged-commands - input-message - dismiss-keyboard))} - (when command? - {:accessibility-label :command-input}) - input-options) - (if command? - input-command - input-message)])) +(defview message-input [input-options] + [command? [:animations :command?] + input-message [:get-chat-input-text] + input-command [:get-chat-command-content]] + [text-input (merge {:style (if command? + st-response/command-input + st-message/message-input) + :ref #(dispatch [:set-message-input %]) + :autoFocus false + :blurOnSubmit false + :onChangeText (if command? + command/set-input-message + plain-message/set-input-message) + :onSubmitEditing (if command? + command/send-command + plain-message/send)} + (when command? + {:accessibility-label :command-input}) + input-options) + (if command? input-command input-message)]) (defview plain-message-input-view [{:keys [input-options validator]}] - [input-message [:get-chat-input-text] - command [:get-chat-command] - command? [:animations :command?] - to-msg-id [:get-chat-command-to-msg-id] + [command? [:animations :command?] input-command [:get-chat-command-content] - staged-commands [:get-chat-staged-commands] - typing-command? [:typing-command?]] - (let [dismiss-keyboard (not (or command typing-command?))] - [view st/input-container - [view st/input-view - [plain-message/commands-button] - [message-input-container - [message-input input-options validator]] - ;; TODO emoticons: not implemented - [plain-message/smile-button] - (if-not command? - (when (plain-message/message-valid? staged-commands input-message) - [send-button {:on-press #(plain-message/try-send staged-commands - input-message - dismiss-keyboard) - :accessibility-label :send-message}]) - (when (command/valid? input-command validator) - [send-button {:on-press command/send-command - :accessibility-label :stage-command}]))]])) + valid-plain-message? [:valid-plain-message?] + valid-command? [:valid-command? validator]] + [view st/input-container + [view st/input-view + [plain-message/commands-button] + [message-input-container + [message-input input-options validator]] + ;; TODO emoticons: not implemented + [plain-message/smile-button] + (when (if command? valid-command? valid-plain-message?) + (let [on-press (if command? + command/send-command + plain-message/send)] + [send-button {:on-press on-press + :accessibility-label :send-message}]))]]) diff --git a/src/status_im/chat/views/plain_message.cljs b/src/status_im/chat/views/plain_message.cljs index b7ecef4e2c..7af02e7142 100644 --- a/src/status_im/chat/views/plain_message.cljs +++ b/src/status_im/chat/views/plain_message.cljs @@ -14,9 +14,7 @@ (defn set-input-message [message] (dispatch [:set-chat-input-text message])) -(defn send [dismiss-keyboard] - (when dismiss-keyboard - (dismiss-keyboard!)) +(defn send [] (dispatch [:send-chat-msg])) (defn message-valid? [staged-commands message] @@ -24,15 +22,6 @@ (not= "!" message)) (pos? (count staged-commands)))) -(defn try-send [staged-commands message dismiss-keyboard] - (when (message-valid? staged-commands message) - (send dismiss-keyboard))) - -(defn prepare-message-input [message-input] - (when message-input - (.clear message-input) - (.focus message-input))) - (defn button-animation-logic [{:keys [command? val]}] (fn [_] (let [to-scale (if @command? 0 1)] From 23b90af0641ee9f0256bd2f0b569dadfe9233b1b Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 20 Jun 2016 21:26:57 +0300 Subject: [PATCH 04/12] abit more refactoring Former-commit-id: 9179cc61b45dd5c42a496cafdcb46ef411150758 --- src/status_im/chat/views/message_input.cljs | 33 +++++++++++---------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/status_im/chat/views/message_input.cljs b/src/status_im/chat/views/message_input.cljs index 67310f8a77..4a63d6cba5 100644 --- a/src/status_im/chat/views/message_input.cljs +++ b/src/status_im/chat/views/message_input.cljs @@ -34,25 +34,28 @@ (defn message-input-container [input] [view st/message-input-container input]) +(def plain-input-options + {:style st-message/message-input + :onChangeText plain-message/set-input-message + :onSubmitEditing plain-message/send}) + +(def command-input-options + {:style st-response/command-input + :onChangeText command/set-input-message + :onSubmitEditing command/send-command}) + (defview message-input [input-options] [command? [:animations :command?] input-message [:get-chat-input-text] input-command [:get-chat-command-content]] - [text-input (merge {:style (if command? - st-response/command-input - st-message/message-input) - :ref #(dispatch [:set-message-input %]) - :autoFocus false - :blurOnSubmit false - :onChangeText (if command? - command/set-input-message - plain-message/set-input-message) - :onSubmitEditing (if command? - command/send-command - plain-message/send)} - (when command? - {:accessibility-label :command-input}) - input-options) + [text-input (merge + (if command? + command-input-options + plain-input-options) + {:autoFocus false + :blurOnSubmit false + :accessibility-label :input} + input-options) (if command? input-command input-message)]) (defview plain-message-input-view [{:keys [input-options validator]}] From 3931c0a1c7666933cda6748eddf9c7674c1ac321 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 21 Jun 2016 10:27:07 +0300 Subject: [PATCH 05/12] hiding of param's suggestions Former-commit-id: ecd7ae26b8517238a8132c1561b28fa9d141498c --- src/status_im/chat/screen.cljs | 5 ++--- src/status_im/chat/views/message_input.cljs | 19 +++---------------- src/status_im/chat/views/plain_message.cljs | 4 ++-- src/status_im/chat/views/response.cljs | 1 + src/status_im/db.cljs | 2 +- 5 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index 2c04ab4859..35e39bf7ef 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -269,8 +269,7 @@ [messages-container [messages-view group-chat]] (when group-chat [typing-all]) - (cond - command? [response-view] - :else [suggestions-view]) + [response-view] + (when-not command? [suggestions-view]) [chat-message-new] (when show-actions-atom [actions-view])]) diff --git a/src/status_im/chat/views/message_input.cljs b/src/status_im/chat/views/message_input.cljs index 4a63d6cba5..fe2900ce63 100644 --- a/src/status_im/chat/views/message_input.cljs +++ b/src/status_im/chat/views/message_input.cljs @@ -1,20 +1,16 @@ (ns status-im.chat.views.message-input (:require-macros [status-im.utils.views :refer [defview]]) - (:require [re-frame.core :refer [subscribe dispatch]] - [reagent.core :as r] + (:require [re-frame.core :refer [subscribe]] [status-im.components.react :refer [view animated-view icon touchable-highlight - text-input - dismiss-keyboard!]] - [status-im.components.animation :as anim] + text-input]] [status-im.chat.views.plain-message :as plain-message] [status-im.chat.views.command :as command] [status-im.chat.styles.message-input :as st] [status-im.chat.styles.plain-message :as st-message] - [status-im.chat.styles.response :as st-response] - [status-im.constants :refer [response-input-hiding-duration]])) + [status-im.chat.styles.response :as st-response])) (defn send-button [{:keys [on-press accessibility-label]}] [touchable-highlight {:on-press on-press @@ -22,15 +18,6 @@ [view st/send-container [icon :send st/send-icon]]]) -(defn animation-logic [{:keys [to-value val]}] - (fn [_] - (let [to-value @to-value] - (anim/start (anim/timing val {:toValue to-value - :duration response-input-hiding-duration}) - (fn [arg] - (when (.-finished arg) - (dispatch [:set-animation ::message-input-offset-current to-value]))))))) - (defn message-input-container [input] [view st/message-input-container input]) diff --git a/src/status_im/chat/views/plain_message.cljs b/src/status_im/chat/views/plain_message.cljs index 7af02e7142..906fa17a93 100644 --- a/src/status_im/chat/views/plain_message.cljs +++ b/src/status_im/chat/views/plain_message.cljs @@ -64,8 +64,8 @@ (let [to-scale (if @command? 0 1)] (when-not @command? (anim/set-value width 56)) (anim/start (anim/spring val {:toValue to-scale}) - (fn [] - (when @command? + (fn [e] + (when (and @command? (.-finished e)) (anim/set-value width 0.1))))))) (defn smile-button [] diff --git a/src/status_im/chat/views/response.cljs b/src/status_im/chat/views/response.cljs index 7ff986e7a8..79f9a772ac 100644 --- a/src/status_im/chat/views/response.cljs +++ b/src/status_im/chat/views/response.cljs @@ -65,6 +65,7 @@ (defn container-animation-logic [{:keys [to-value val]}] (fn [_] + (println :to @to-value) (let [to-value @to-value] (anim/start (anim/spring val {:toValue to-value}))))) diff --git a/src/status_im/db.cljs b/src/status_im/db.cljs index e118920433..675606a664 100644 --- a/src/status_im/db.cljs +++ b/src/status_im/db.cljs @@ -37,7 +37,7 @@ :whisper-identity "" :phone-number ""} :disable-group-creation false - :animations {:to-response-height nil + :animations {:to-response-height 0.1 :response-height-current nil :command? false :messages-offset 0 From ed35391d7fb6492972bc1f94fd066bc14023fc29 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 21 Jun 2016 10:56:11 +0300 Subject: [PATCH 06/12] command animation Former-commit-id: 8c1d2eec1afe421b5419d87598a01f9b832fc86a --- src/status_im/chat/handlers.cljs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 05f1bef3a7..9c33efff4f 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -253,9 +253,11 @@ (commands/unstage-command db staged-command))) (register-handler :set-chat-command + (after #(dispatch [:animate-show-response])) (fn [db [_ command-key]] - ;; todo what is going on there?! - (commands/set-chat-command db command-key))) + (-> db + (commands/set-chat-command command-key) + (assoc-in [:animations :command?] true)))) (register-handler :init-console-chat (fn [db [_]] From 4e39130176b7f3e8f3f923a5fdb268eb1fda097f Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 21 Jun 2016 11:35:15 +0300 Subject: [PATCH 07/12] keyboard height Former-commit-id: e6639fc770cedd7f52bb272f0071c3f0cb9ec8be --- src/status_im/android/core.cljs | 44 ++++++++++++++++---------- src/status_im/chat/views/response.cljs | 7 ++-- src/status_im/components/react.cljs | 1 + 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index 154c7104ce..daecbff91c 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -5,7 +5,7 @@ [re-frame.core :refer [subscribe dispatch dispatch-sync]] [status-im.handlers] [status-im.subs] - [status-im.components.react :refer [navigator app-registry]] + [status-im.components.react :refer [navigator app-registry device-event-emitter]] [status-im.components.main-tabs :refer [main-tabs]] [status-im.contacts.screen :refer [contact-list]] [status-im.contacts.views.new-contact :refer [new-contact]] @@ -36,21 +36,33 @@ (defn app-root [] (let [signed-up (subscribe [:get :signed-up]) view-id (subscribe [:get :view-id])] - (fn [] - (case (if @signed-up @view-id :chat) - :discovery [main-tabs] - :discovery-tag [discovery-tag] - :add-participants [new-participants] - :remove-participants [remove-participants] - :chat-list [main-tabs] - :new-group [new-group] - :group-settings [group-settings] - :contact-list [main-tabs] - :new-contact [new-contact] - :qr-scanner [qr-scanner] - :chat [chat] - :profile [profile] - :my-profile [my-profile])))) + (r/create-class + {:component-will-mount + (fn [] + (.addListener device-event-emitter + "keyboardDidShow" + (fn [e] + (let [h (.. e -endCoordinates -height)] + (dispatch [:set :keyboard-height h])))) + (.addListener device-event-emitter + "keyboardDidHide" + #(dispatch [:set :keyboard-height 0]))) + :render + (fn [] + (case (if @signed-up @view-id :chat) + :discovery [main-tabs] + :discovery-tag [discovery-tag] + :add-participants [new-participants] + :remove-participants [remove-participants] + :chat-list [main-tabs] + :new-group [new-group] + :group-settings [group-settings] + :contact-list [main-tabs] + :new-contact [new-contact] + :qr-scanner [qr-scanner] + :chat [chat] + :profile [profile] + :my-profile [my-profile]))}))) (defn init [] (dispatch-sync [:initialize-db]) diff --git a/src/status_im/chat/views/response.cljs b/src/status_im/chat/views/response.cljs index 79f9a772ac..8566da3bb9 100644 --- a/src/status_im/chat/views/response.cljs +++ b/src/status_im/chat/views/response.cljs @@ -34,11 +34,12 @@ ;; TODO stub data: request message info "By ???, MMM 1st at HH:mm"]]) -(defn create-response-pan-responder [response-height] +(defn create-response-pan-responder [response-height kb-height] (drag/create-pan-responder {:on-move (fn [_ gesture] (when (> (Math/abs (.-dy gesture)) 10) (let [to-value (- (:height (react/get-dimensions "window")) + @kb-height (.-moveY gesture))] (anim/start (anim/spring response-height {:toValue to-value}))))) @@ -50,7 +51,8 @@ (.-_value response-height)])))})) (defn request-info [response-height] - (let [pan-responder (create-response-pan-responder response-height) + (let [kb-height (subscribe [:get :keyboard-height]) + pan-responder (create-response-pan-responder response-height kb-height) command (subscribe [:get-chat-command])] (fn [response-height] [view (merge (drag/pan-handlers pan-responder) @@ -65,7 +67,6 @@ (defn container-animation-logic [{:keys [to-value val]}] (fn [_] - (println :to @to-value) (let [to-value @to-value] (anim/start (anim/spring val {:toValue to-value}))))) diff --git a/src/status_im/components/react.cljs b/src/status_im/components/react.cljs index 1347f22ea2..3841331b14 100644 --- a/src/status_im/components/react.cljs +++ b/src/status_im/components/react.cljs @@ -76,3 +76,4 @@ (r/as-element component)) (def dismiss-keyboard! (u/require "dismissKeyboard")) +(def device-event-emitter (.-DeviceEventEmitter react)) From 6beda2ace206f71c60a200571e6e119ab23c5f81 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 21 Jun 2016 12:03:39 +0300 Subject: [PATCH 08/12] orientation Former-commit-id: f7b583270707f4fcfc599f9010c3dcba58c1decc --- android/app/build.gradle | 1 + .../main/java/com/statusim/MainActivity.java | 15 ++++++++++-- android/settings.gradle | 2 ++ package.json | 1 + src/status_im/android/core.cljs | 11 ++++++++- src/status_im/chat/views/response.cljs | 23 +++++++++++-------- src/status_im/components/react.cljs | 1 + 7 files changed, 42 insertions(+), 12 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 21e197ea42..7202b12494 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -131,6 +131,7 @@ dependencies { compile project(':react-native-linear-gradient') compile project(':ReactNativeAndroidSmsListener') compile project(':react-native-camera') + compile project(':react-native-orientation') // compile(name:'geth', ext:'aar') compile(group: 'status-im', name: 'android-geth', version: '1.4.0-201604110816-a97a114', ext: 'aar') diff --git a/android/app/src/main/java/com/statusim/MainActivity.java b/android/app/src/main/java/com/statusim/MainActivity.java index 341732d5d7..ee5ff65fd1 100644 --- a/android/app/src/main/java/com/statusim/MainActivity.java +++ b/android/app/src/main/java/com/statusim/MainActivity.java @@ -23,6 +23,7 @@ import android.content.Context; import com.bitgo.randombytes.RandomBytesPackage; import com.BV.LinearGradient.LinearGradientPackage; import com.centaurwarchief.smslistener.SmsListener; +import com.github.yamill.orientation.OrientationPackage; import android.util.Log; @@ -35,7 +36,8 @@ import java.io.File; import com.lwansbrough.RCTCamera.*; import com.i18n.reactnativei18n.ReactNativeI18n; import io.realm.react.RealmReactPackage; - +import android.content.Intent; +import android.content.res.Configuration; public class MainActivity extends ReactActivity { @@ -181,7 +183,16 @@ public class MainActivity extends ReactActivity { new RandomBytesPackage(), new LinearGradientPackage(), new RCTCameraPackage(), - new SmsListener(this) + new SmsListener(this), + new OrientationPackage(this) ); } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + Intent intent = new Intent("onConfigurationChanged"); + intent.putExtra("newConfig", newConfig); + this.sendBroadcast(intent); + } } diff --git a/android/settings.gradle b/android/settings.gradle index 906ece37bc..ee6b7c66b3 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -20,3 +20,5 @@ include ':ReactNativeAndroidSmsListener' project(':ReactNativeAndroidSmsListener').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-sms-listener/android') include ':react-native-camera' project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android') +include ':react-native-orientation', ':app' +project(':react-native-orientation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-orientation/android') diff --git a/package.json b/package.json index b26cf32faf..7a3bdd9292 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "react-native-qrcode": "^0.2.2", "react-native-randombytes": "^2.1.0", "react-native-vector-icons": "^1.3.4", + "react-native-orientation": "^1.17.0", "realm": "^0.11.1" } } diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index daecbff91c..bba5331ebf 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -5,7 +5,8 @@ [re-frame.core :refer [subscribe dispatch dispatch-sync]] [status-im.handlers] [status-im.subs] - [status-im.components.react :refer [navigator app-registry device-event-emitter]] + [status-im.components.react :refer [navigator app-registry device-event-emitter + orientation]] [status-im.components.main-tabs :refer [main-tabs]] [status-im.contacts.screen :refer [contact-list]] [status-im.contacts.views.new-contact :refer [new-contact]] @@ -33,12 +34,20 @@ true)))] (add-event-listener "hardwareBackPress" new-listener))) +(defn orientation->keyword [o] + (keyword (.toLowerCase o))) + (defn app-root [] (let [signed-up (subscribe [:get :signed-up]) view-id (subscribe [:get :view-id])] (r/create-class {:component-will-mount (fn [] + (let [o (orientation->keyword (.getInitialOrientation orientation))] + (dispatch [:set :orientation o])) + (.addOrientationListener + orientation + #(dispatch [:set :orientation (orientation->keyword %)])) (.addListener device-event-emitter "keyboardDidShow" (fn [e] diff --git a/src/status_im/chat/views/response.cljs b/src/status_im/chat/views/response.cljs index 8566da3bb9..dc41bf1833 100644 --- a/src/status_im/chat/views/response.cljs +++ b/src/status_im/chat/views/response.cljs @@ -34,11 +34,15 @@ ;; TODO stub data: request message info "By ???, MMM 1st at HH:mm"]]) -(defn create-response-pan-responder [response-height kb-height] +(defn pan-responder [response-height kb-height orientation] (drag/create-pan-responder {:on-move (fn [_ gesture] (when (> (Math/abs (.-dy gesture)) 10) - (let [to-value (- (:height (react/get-dimensions "window")) + (let [w (react/get-dimensions "window") + p (if (= :portrait @orientation) + :height + :width) + to-value (- (p w) @kb-height (.-moveY gesture))] (anim/start @@ -51,8 +55,9 @@ (.-_value response-height)])))})) (defn request-info [response-height] - (let [kb-height (subscribe [:get :keyboard-height]) - pan-responder (create-response-pan-responder response-height kb-height) + (let [orientation (subscribe [:get :orientation]) + kb-height (subscribe [:get :keyboard-height]) + pan-responder (pan-responder response-height kb-height orientation) command (subscribe [:get-chat-command])] (fn [response-height] [view (merge (drag/pan-handlers pan-responder) @@ -73,11 +78,11 @@ (defn container [response-height & children] (let [;; todo to-response-height, cur-response-height must be specific ;; for each chat - to-response-height (subscribe [:animations :to-response-height]) - changed (subscribe [:animations :response-height-changed]) - context {:to-value to-response-height - :val response-height} - on-update (container-animation-logic context)] + to-response-height (subscribe [:animations :to-response-height]) + changed (subscribe [:animations :response-height-changed]) + context {:to-value to-response-height + :val response-height} + on-update (container-animation-logic context)] (r/create-class {:component-did-mount on-update diff --git a/src/status_im/components/react.cljs b/src/status_im/components/react.cljs index 3841331b14..f931ce4e00 100644 --- a/src/status_im/components/react.cljs +++ b/src/status_im/components/react.cljs @@ -77,3 +77,4 @@ (def dismiss-keyboard! (u/require "dismissKeyboard")) (def device-event-emitter (.-DeviceEventEmitter react)) +(def orientation (u/require "react-native-orientation")) From 36bddaff1f5fac285846965e33483d14944f2ad5 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 21 Jun 2016 12:23:02 +0300 Subject: [PATCH 09/12] cleanup Former-commit-id: 4d7476dc5b0bf50f6b67afd7f831a03a04db74ab --- src/status_im/chat/handlers.cljs | 5 ---- src/status_im/chat/handlers/animation.cljs | 27 ++-------------------- src/status_im/chat/views/response.cljs | 17 ++++++++------ src/status_im/db.cljs | 4 +--- 4 files changed, 13 insertions(+), 40 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 9c33efff4f..db7c198ec3 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -50,12 +50,7 @@ (fn [db _] (dispatch [:animate-cancel-command])))) -(defn animate-set-chat-command-content [db _] - (when (commands/get-chat-command-to-msg-id db) - (dispatch [:animate-response-resize]))) - (register-handler :set-chat-command-content - (after animate-set-chat-command-content) (fn [{:keys [current-chat-id] :as db} [_ content]] (as-> db db (commands/set-chat-command-content db content) diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index f296ea73d8..66869b356d 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -22,20 +22,6 @@ :to-response-height zero-height :messages-offset 0))) -(animation-handler :finish-animate-response-resize - (fn [db _] - (let [fixed (:to-response-height db)] - (assoc db :response-height-current fixed - :response-resize? false)))) - -(animation-handler :set-response-height - (fn [db [_ value]] - (assoc db :response-height-current value))) - -(animation-handler :animate-response-resize - (fn [db _] - (assoc db :response-resize? true))) - (defn get-response-height [db] (let [command (commands/get-chat-command db) text (commands/get-chat-command-content db) @@ -51,10 +37,8 @@ (assoc-in db [:animations :to-response-height] (get-response-height db))) (register-handler :animate-show-response - (after #(dispatch [:animate-response-resize])) (fn [db _] (-> db - (assoc-in [:animations :response-height-current] zero-height) (assoc-in [:animations :command?] true) (assoc-in [:animations :messages-offset] request-info-height) (update-response-height)))) @@ -65,19 +49,12 @@ (if (not= height prev-height) (let [db (assoc db :response-height-max height)] (if (= prev-height (:to-response-height db)) - (assoc db :to-response-height height - :response-height-current height) + (assoc db :to-response-height height) db)) db)))) -(animation-handler :on-drag-response - (fn [db [_ dy]] - (let [fixed (:to-response-height db)] - (assoc db :response-height-current (- fixed dy) - :response-resize? false)))) - (register-handler :fix-response-height - (fn [db [_ dy vy current]] + (fn [db [_ vy current]] (let [max-height (get-in db [:animations :response-height-max]) ;; todo magic value middle 270 diff --git a/src/status_im/chat/views/response.cljs b/src/status_im/chat/views/response.cljs index dc41bf1833..c9d4870c78 100644 --- a/src/status_im/chat/views/response.cljs +++ b/src/status_im/chat/views/response.cljs @@ -34,24 +34,27 @@ ;; TODO stub data: request message info "By ???, MMM 1st at HH:mm"]]) +;; todo bad name. Ideas? +(defn enough-dy [gesture] + (> (Math/abs (.-dy gesture)) 10)) + (defn pan-responder [response-height kb-height orientation] (drag/create-pan-responder {:on-move (fn [_ gesture] - (when (> (Math/abs (.-dy gesture)) 10) + (when (enough-dy gesture) (let [w (react/get-dimensions "window") - p (if (= :portrait @orientation) + prop (if (= :portrait @orientation) :height :width) - to-value (- (p w) - @kb-height - (.-moveY gesture))] + to-value (- (prop w) @kb-height (.-moveY gesture))] (anim/start (anim/spring response-height {:toValue to-value}))))) :on-release (fn [_ gesture] - (when (> (Math/abs (.-dy gesture)) 10) + (when (enough-dy gesture) (dispatch [:fix-response-height - (.-dy gesture) (.-vy gesture) + ;; todo access to "private" property + ;; better to find another way... (.-_value response-height)])))})) (defn request-info [response-height] diff --git a/src/status_im/db.cljs b/src/status_im/db.cljs index 675606a664..c10422e8f7 100644 --- a/src/status_im/db.cljs +++ b/src/status_im/db.cljs @@ -38,10 +38,8 @@ :phone-number ""} :disable-group-creation false :animations {:to-response-height 0.1 - :response-height-current nil :command? false - :messages-offset 0 - :response-resize? false}}) + :messages-offset 0}}) (def protocol-initialized-path [:protocol-initialized]) (defn chat-input-text-path [chat-id] From 4f6ac06fa9f7eb6f52754d59a87d4d01c0abde50 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 21 Jun 2016 12:46:02 +0300 Subject: [PATCH 10/12] edit mode Former-commit-id: d6040491fb570470ee051492a32070b629f88066 --- src/status_im/chat/handlers.cljs | 20 +++++++++++++++----- src/status_im/chat/handlers/animation.cljs | 4 ++-- src/status_im/chat/screen.cljs | 2 +- src/status_im/chat/subs.cljs | 6 ++++++ src/status_im/chat/views/message_input.cljs | 4 ++-- src/status_im/chat/views/new_message.cljs | 2 +- src/status_im/chat/views/plain_message.cljs | 4 ++-- src/status_im/db.cljs | 1 - 8 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index db7c198ec3..ae8cdd5dc0 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -86,7 +86,8 @@ (.blur message-input))))) (register-handler :set-response-chat-command - (after #(dispatch [:animate-show-response])) + [(after #(dispatch [:command-edit-mode])) + (after #(dispatch [:animate-show-response]))] (fn [db [_ to-msg-id command-key]] (commands/set-response-chat-command db to-msg-id command-key))) @@ -248,11 +249,10 @@ (commands/unstage-command db staged-command))) (register-handler :set-chat-command - (after #(dispatch [:animate-show-response])) + [(after #(dispatch [:command-edit-mode])) + (after #(dispatch [:animate-show-response]))] (fn [db [_ command-key]] - (-> db - (commands/set-chat-command command-key) - (assoc-in [:animations :command?] true)))) + (commands/set-chat-command db command-key))) (register-handler :init-console-chat (fn [db [_]] @@ -428,3 +428,13 @@ ;((after leaving-message!)) ((after delete-messages!)) ((after delete-chat!)))) + +(defn edit-mode-handler [mode] + (fn [{:keys [current-chat-id] :as db} _] + (assoc-in db [:edit-mode current-chat-id] mode))) + +(register-handler :command-edit-mode + (edit-mode-handler :command)) + +(register-handler :text-edit-mode + (edit-mode-handler :text)) diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index 66869b356d..994a32e85f 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -16,9 +16,9 @@ (register-handler name [(path :animations) middleware] handler))) (animation-handler :animate-cancel-command + (after #(dispatch [:text-edit-mode])) (fn [db _] (assoc db - :command? false :to-response-height zero-height :messages-offset 0))) @@ -37,9 +37,9 @@ (assoc-in db [:animations :to-response-height] (get-response-height db))) (register-handler :animate-show-response + (after #(dispatch [:command-edit-mode])) (fn [db _] (-> db - (assoc-in [:animations :command?] true) (assoc-in [:animations :messages-offset] request-info-height) (update-response-height)))) diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index 35e39bf7ef..4927858f1e 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -259,7 +259,7 @@ [group-chat [:chat :group-chat] show-actions-atom [:show-actions] command [:get-chat-command] - command? [:animations :command?] + command? [:command?] to-msg-id [:get-chat-command-to-msg-id]] [view {:style st/chat-view :onLayout (fn [event] diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index 4486741df5..804085ad4b 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -111,3 +111,9 @@ (let [command (reaction (commands/get-chat-command @db)) text (reaction (commands/get-chat-command-content @db))] (reaction (get-content-suggestions @command @text))))) + +(register-sub :command? + (fn [db ] + (->> (get-in @db [:edit-mode (:current-chat-id @db)]) + (= :command) + (reaction)))) diff --git a/src/status_im/chat/views/message_input.cljs b/src/status_im/chat/views/message_input.cljs index fe2900ce63..1df66f9c3d 100644 --- a/src/status_im/chat/views/message_input.cljs +++ b/src/status_im/chat/views/message_input.cljs @@ -32,7 +32,7 @@ :onSubmitEditing command/send-command}) (defview message-input [input-options] - [command? [:animations :command?] + [command? [:command?] input-message [:get-chat-input-text] input-command [:get-chat-command-content]] [text-input (merge @@ -46,7 +46,7 @@ (if command? input-command input-message)]) (defview plain-message-input-view [{:keys [input-options validator]}] - [command? [:animations :command?] + [command? [:command?] input-command [:get-chat-command-content] valid-plain-message? [:valid-plain-message?] valid-command? [:valid-command? validator]] diff --git a/src/status_im/chat/views/new_message.cljs b/src/status_im/chat/views/new_message.cljs index e8e53d2681..cb5865a5d0 100644 --- a/src/status_im/chat/views/new_message.cljs +++ b/src/status_im/chat/views/new_message.cljs @@ -18,7 +18,7 @@ (defview show-input [] [command [:get-chat-command] - command? [:animations :command?]] + command? [:command?]] [plain-message-input-view (when command? (case (:command command) diff --git a/src/status_im/chat/views/plain_message.cljs b/src/status_im/chat/views/plain_message.cljs index 906fa17a93..b5fef1c43c 100644 --- a/src/status_im/chat/views/plain_message.cljs +++ b/src/status_im/chat/views/plain_message.cljs @@ -36,7 +36,7 @@ :delay delay}))))) (defn commands-button [] - (let [command? (subscribe [:animations :command?]) + (let [command? (subscribe [:command?]) buttons-scale (anim/create-value (if @command? 1 0)) container-width (anim/create-value (if @command? 20 56)) context {:command? command? @@ -69,7 +69,7 @@ (anim/set-value width 0.1))))))) (defn smile-button [] - (let [command? (subscribe [:animations :command?]) + (let [command? (subscribe [:command?]) buttons-scale (anim/create-value (if @command? 1 0)) container-width (anim/create-value (if @command? 0.1 56)) context {:command? command? diff --git a/src/status_im/db.cljs b/src/status_im/db.cljs index c10422e8f7..c5b87f3448 100644 --- a/src/status_im/db.cljs +++ b/src/status_im/db.cljs @@ -38,7 +38,6 @@ :phone-number ""} :disable-group-creation false :animations {:to-response-height 0.1 - :command? false :messages-offset 0}}) (def protocol-initialized-path [:protocol-initialized]) From 6545e27465232008a6085cbedd2cbc53c5d58bac Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 21 Jun 2016 13:04:08 +0300 Subject: [PATCH 11/12] orientation module Former-commit-id: 84e9ea897f91a93c99ef895f64dc03a968a78f29 --- .re-natal | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.re-natal b/.re-natal index 4fecaf5ca5..da7df24c66 100644 --- a/.re-natal +++ b/.re-natal @@ -1,7 +1,7 @@ { "name": "StatusIm", "interface": "reagent", - "androidHost": "10.0.3.2", + "androidHost": "localhost", "modules": [ "react-native-contacts", "react-native-invertible-scroll-view", @@ -18,7 +18,8 @@ "react-native-linear-gradient", "react-native-android-sms-listener", "react-native-camera", - "react-native-qrcode" + "react-native-qrcode", + "react-native-orientation" ], "imageDirs": [ "images" From 977e29f4c349cf20100675725f06000e3582519b Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 21 Jun 2016 20:13:51 +0300 Subject: [PATCH 12/12] comments Former-commit-id: 2887e1c5027f3aa733f4ab60088e6d962b2b2c98 --- src/status_im/chat/views/response.cljs | 44 ++++++++++++++++---------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/src/status_im/chat/views/response.cljs b/src/status_im/chat/views/response.cljs index c9d4870c78..56382052c8 100644 --- a/src/status_im/chat/views/response.cljs +++ b/src/status_im/chat/views/response.cljs @@ -38,24 +38,36 @@ (defn enough-dy [gesture] (> (Math/abs (.-dy gesture)) 10)) +(defn on-move [response-height kb-height orientation] + (fn [_ gesture] + (when (enough-dy gesture) + (let [w (react/get-dimensions "window") + ;; depending on orientation use height or width of screen + prop (if (= :portrait @orientation) + :height + :width) + ;; subtract keyboard height to get "real height" of screen + ;; then subtract gesture position to get suggestions height + ;; todo maybe it is better to use margin-top instead height + ;; it is not obvious + to-value (- (prop w) @kb-height (.-moveY gesture))] + (println to-value ) + (anim/start + (anim/spring response-height {:toValue to-value})))))) + +(defn on-release [response-height] + (fn [_ gesture] + (when (enough-dy gesture) + (dispatch [:fix-response-height + (.-vy gesture) + ;; todo access to "private" property + ;; better to find another way... + (.-_value response-height)])))) + (defn pan-responder [response-height kb-height orientation] (drag/create-pan-responder - {:on-move (fn [_ gesture] - (when (enough-dy gesture) - (let [w (react/get-dimensions "window") - prop (if (= :portrait @orientation) - :height - :width) - to-value (- (prop w) @kb-height (.-moveY gesture))] - (anim/start - (anim/spring response-height {:toValue to-value}))))) - :on-release (fn [_ gesture] - (when (enough-dy gesture) - (dispatch [:fix-response-height - (.-vy gesture) - ;; todo access to "private" property - ;; better to find another way... - (.-_value response-height)])))})) + {:on-move (on-move response-height kb-height orientation) + :on-release (on-release response-height)})) (defn request-info [response-height] (let [orientation (subscribe [:get :orientation])