separate animations values for different chats

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

View File

@ -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

View File

@ -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])))))

View File

@ -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}

View File

@ -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}

View File

@ -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])