From 65772e3438230aef52466e9bf596dc5943e2cac3 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Fri, 8 Jul 2016 18:30:16 +0300 Subject: [PATCH] separate animations values for different chats --- src/status_im/chat/handlers/animation.cljs | 30 ++++++++++++---------- src/status_im/chat/subs.cljs | 12 +++++++++ src/status_im/chat/views/response.cljs | 4 +-- src/status_im/chat/views/suggestions.cljs | 2 +- src/status_im/db.cljs | 3 +-- 5 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index 1bb6913651..0a92615c7d 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -3,6 +3,7 @@ [status-im.utils.handlers :refer [register-handler]] [status-im.handlers.content-suggestions :refer [get-content-suggestions]] [status-im.chat.constants :refer [input-height request-info-height + suggestions-header-height minimum-command-suggestions-height response-height-normal minimum-suggestion-height]] [status-im.constants :refer [response-input-hiding-duration]])) @@ -15,27 +16,28 @@ ([name middleware handler] (register-handler name [(path :animations) middleware] handler))) -(animation-handler :animate-cancel-command +(register-handler :animate-cancel-command (after #(dispatch [:text-edit-mode])) - (fn [db _] - (assoc db :to-response-height input-height))) + (fn [{:keys [current-chat-id] :as db} _] + (assoc-in db [:animations :to-response-height current-chat-id] input-height))) (def response-height (+ input-height response-height-normal)) -(defn update-response-height [db] - (assoc-in db [:animations :to-response-height] response-height)) +(defn update-response-height + [{:keys [current-chat-id] :as db}] + (assoc-in db [:animations :to-response-height current-chat-id] response-height)) (register-handler :animate-command-suggestions - (fn [{:keys [current-chat-id] :as db} _] - (let [suggestions? (seq (get-in db [:command-suggestions current-chat-id])) - current (get-in db [:animations :command-suggestions-height]) + (fn [{chat-id :current-chat-id :as db} _] + (let [suggestions? (seq (get-in db [:command-suggestions chat-id])) + current (get-in db [:animations :command-suggestions-height chat-id]) height (if suggestions? middle-height input-height) changed? (if (and suggestions? (not (nil? current)) (not= input-height current)) identity inc)] (-> db - (update :animations assoc :command-suggestions-height height) + (assoc-in [:animations :command-suggestions-height chat-id] height) (update-in [:animations :commands-height-changed] changed?))))) (defn get-minimum-height @@ -50,7 +52,9 @@ (+ validation-height (if (= :response type) minimum-suggestion-height - input-height)))) + (if (zero? validation-height) + input-height + (+ input-height suggestions-header-height)))))) (register-handler :animate-show-response ;[(after #(dispatch [:command-edit-mode]))] @@ -59,7 +63,7 @@ height (if suggestions? middle-height (get-minimum-height db))] - (assoc-in db [:animations :to-response-height] height)))) + (assoc-in db [:animations :to-response-height current-chat-id] height)))) (defn fix-height [height-key height-signal-key suggestions-key minimum] @@ -70,7 +74,7 @@ under-middle-position? (<= current middle-height) over-middle-position? (not under-middle-position?) suggestions (get-in db [suggestions-key current-chat-id]) - old-fixed (get-in db [:animations height-key]) + old-fixed (get-in db [:animations height-key current-chat-id]) new-fixed (cond (not suggestions) (minimum db) @@ -95,7 +99,7 @@ (and under-middle-position? moving-down?) (minimum db))] (-> db - (assoc-in [:animations height-key] new-fixed) + (assoc-in [:animations height-key current-chat-id] new-fixed) (update-in [:animations height-signal-key] inc))))) (defn commands-min-height diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index c1a8d722b3..edef877e45 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -186,3 +186,15 @@ (register-sub :unviewed-messages-count (fn [db [_ chat-id]] (reaction (get-in @db [:unviewed-messages chat-id :count])))) + +(register-sub :command-suggestions-height + (fn [db] + (let [chat-id (subscribe [:get-current-chat-id])] + (reaction + (get-in @db [:animations :command-suggestions-height @chat-id]))))) + +(register-sub :response-height + (fn [db] + (let [chat-id (subscribe [:get-current-chat-id])] + (reaction + (get-in @db [:animations :to-response-height @chat-id]))))) diff --git a/src/status_im/chat/views/response.cljs b/src/status_im/chat/views/response.cljs index 6e016f5e00..1e7d9d7d3d 100644 --- a/src/status_im/chat/views/response.cljs +++ b/src/status_im/chat/views/response.cljs @@ -59,14 +59,14 @@ [icon :drag_down ddst/drag-down-icon]])))) (defn container-animation-logic [{:keys [to-value val]}] - (let [to-value @to-value] + (when-let [to-value @to-value] (when-not (= to-value (.-_value val)) (anim/start (anim/spring val {:toValue to-value}))))) (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]) + to-response-height (subscribe [:response-height]) changed (subscribe [:animations :response-height-changed]) context {:to-value to-response-height :val response-height} diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index 909641d829..5a97ed7e3d 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -104,7 +104,7 @@ (defn container [h & elements] (let [;; todo to-response-height, cur-response-height must be specific ;; for each chat - to-response-height (subscribe [:animations :command-suggestions-height]) + to-response-height (subscribe [:command-suggestions-height]) changed (subscribe [:animations :commands-height-changed]) context {:to-value to-response-height :val h} diff --git a/src/status_im/db.cljs b/src/status_im/db.cljs index 9d1cc6fa5d..503ca17a99 100644 --- a/src/status_im/db.cljs +++ b/src/status_im/db.cljs @@ -38,8 +38,7 @@ :whisper-identity "" :phone-number ""} :disable-group-creation false - :animations {:to-response-height 0.1 - ;; todo clear this + :animations {;; todo clear this :tabs-bar-value (anim/create-value 0)}}) (def protocol-initialized-path [:protocol-initialized])