separate animations values for different chats

Former-commit-id: 65772e3438
This commit is contained in:
Roman Volosovskyi 2016-07-08 18:30:16 +03:00
parent 79f3ed036e
commit 5a44a15597
5 changed files with 33 additions and 18 deletions

View File

@ -3,6 +3,7 @@
[status-im.utils.handlers :refer [register-handler]] [status-im.utils.handlers :refer [register-handler]]
[status-im.handlers.content-suggestions :refer [get-content-suggestions]] [status-im.handlers.content-suggestions :refer [get-content-suggestions]]
[status-im.chat.constants :refer [input-height request-info-height [status-im.chat.constants :refer [input-height request-info-height
suggestions-header-height
minimum-command-suggestions-height minimum-command-suggestions-height
response-height-normal minimum-suggestion-height]] response-height-normal minimum-suggestion-height]]
[status-im.constants :refer [response-input-hiding-duration]])) [status-im.constants :refer [response-input-hiding-duration]]))
@ -15,27 +16,28 @@
([name middleware handler] ([name middleware handler]
(register-handler name [(path :animations) middleware] handler))) (register-handler name [(path :animations) middleware] handler)))
(animation-handler :animate-cancel-command (register-handler :animate-cancel-command
(after #(dispatch [:text-edit-mode])) (after #(dispatch [:text-edit-mode]))
(fn [db _] (fn [{:keys [current-chat-id] :as db} _]
(assoc db :to-response-height input-height))) (assoc-in db [:animations :to-response-height current-chat-id] input-height)))
(def response-height (+ input-height response-height-normal)) (def response-height (+ input-height response-height-normal))
(defn update-response-height [db] (defn update-response-height
(assoc-in db [:animations :to-response-height] 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 (register-handler :animate-command-suggestions
(fn [{:keys [current-chat-id] :as db} _] (fn [{chat-id :current-chat-id :as db} _]
(let [suggestions? (seq (get-in db [:command-suggestions current-chat-id])) (let [suggestions? (seq (get-in db [:command-suggestions chat-id]))
current (get-in db [:animations :command-suggestions-height]) current (get-in db [:animations :command-suggestions-height chat-id])
height (if suggestions? middle-height input-height) height (if suggestions? middle-height input-height)
changed? (if (and suggestions? changed? (if (and suggestions?
(not (nil? current)) (not (nil? current))
(not= input-height current)) (not= input-height current))
identity inc)] identity inc)]
(-> db (-> db
(update :animations assoc :command-suggestions-height height) (assoc-in [:animations :command-suggestions-height chat-id] height)
(update-in [:animations :commands-height-changed] changed?))))) (update-in [:animations :commands-height-changed] changed?)))))
(defn get-minimum-height (defn get-minimum-height
@ -50,7 +52,9 @@
(+ validation-height (+ validation-height
(if (= :response type) (if (= :response type)
minimum-suggestion-height minimum-suggestion-height
input-height)))) (if (zero? validation-height)
input-height
(+ input-height suggestions-header-height))))))
(register-handler :animate-show-response (register-handler :animate-show-response
;[(after #(dispatch [:command-edit-mode]))] ;[(after #(dispatch [:command-edit-mode]))]
@ -59,7 +63,7 @@
height (if suggestions? height (if suggestions?
middle-height middle-height
(get-minimum-height db))] (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 (defn fix-height
[height-key height-signal-key suggestions-key minimum] [height-key height-signal-key suggestions-key minimum]
@ -70,7 +74,7 @@
under-middle-position? (<= current middle-height) under-middle-position? (<= current middle-height)
over-middle-position? (not under-middle-position?) over-middle-position? (not under-middle-position?)
suggestions (get-in db [suggestions-key current-chat-id]) 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) new-fixed (cond (not suggestions)
(minimum db) (minimum db)
@ -95,7 +99,7 @@
(and under-middle-position? moving-down?) (and under-middle-position? moving-down?)
(minimum db))] (minimum db))]
(-> 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))))) (update-in [:animations height-signal-key] inc)))))
(defn commands-min-height (defn commands-min-height

View File

@ -186,3 +186,15 @@
(register-sub :unviewed-messages-count (register-sub :unviewed-messages-count
(fn [db [_ chat-id]] (fn [db [_ chat-id]]
(reaction (get-in @db [:unviewed-messages chat-id :count])))) (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])))))

View File

@ -59,14 +59,14 @@
[icon :drag_down ddst/drag-down-icon]])))) [icon :drag_down ddst/drag-down-icon]]))))
(defn container-animation-logic [{:keys [to-value val]}] (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)) (when-not (= to-value (.-_value val))
(anim/start (anim/spring val {:toValue to-value}))))) (anim/start (anim/spring val {:toValue to-value})))))
(defn container [response-height & children] (defn container [response-height & children]
(let [;; todo to-response-height, cur-response-height must be specific (let [;; todo to-response-height, cur-response-height must be specific
;; for each chat ;; for each chat
to-response-height (subscribe [:animations :to-response-height]) to-response-height (subscribe [:response-height])
changed (subscribe [:animations :response-height-changed]) changed (subscribe [:animations :response-height-changed])
context {:to-value to-response-height context {:to-value to-response-height
:val response-height} :val response-height}

View File

@ -104,7 +104,7 @@
(defn container [h & elements] (defn container [h & elements]
(let [;; todo to-response-height, cur-response-height must be specific (let [;; todo to-response-height, cur-response-height must be specific
;; for each chat ;; for each chat
to-response-height (subscribe [:animations :command-suggestions-height]) to-response-height (subscribe [:command-suggestions-height])
changed (subscribe [:animations :commands-height-changed]) changed (subscribe [:animations :commands-height-changed])
context {:to-value to-response-height context {:to-value to-response-height
:val h} :val h}

View File

@ -38,8 +38,7 @@
:whisper-identity "" :whisper-identity ""
:phone-number ""} :phone-number ""}
:disable-group-creation false :disable-group-creation false
:animations {:to-response-height 0.1 :animations {;; todo clear this
;; todo clear this
:tabs-bar-value (anim/create-value 0)}}) :tabs-bar-value (anim/create-value 0)}})
(def protocol-initialized-path [:protocol-initialized]) (def protocol-initialized-path [:protocol-initialized])