Animation refactoring

This commit is contained in:
virvar 2016-05-31 17:05:31 +03:00
parent 96ef6c34a8
commit 5c83b09db6
1 changed files with 17 additions and 19 deletions

View File

@ -49,27 +49,28 @@
(assoc-in [:chats current-chat-id :command-input] {}) (assoc-in [:chats current-chat-id :command-input] {})
(update-in [:chats current-chat-id :input-text] safe-trim)))) (update-in [:chats current-chat-id :input-text] safe-trim))))
(defn animate-cancel-command [db height-anim-value] (defn animate-cancel-command! [db]
(let [to-value 1] (let [height-anim-value (get-in db [:animations :response-suggestions-height])
to-value 1]
(anim/add-listener height-anim-value (anim/add-listener height-anim-value
(fn [val] (fn [val]
(when (<= (- to-value delta) (anim/value val) (+ to-value delta)) (when (<= (- to-value delta) (anim/value val) (+ to-value delta))
(anim/remove-all-listeners height-anim-value) (anim/remove-all-listeners height-anim-value)
(dispatch [:cancel-command])))) (dispatch [:cancel-command]))))
(anim/stop-animation height-anim-value)
(anim/start (anim/spring height-anim-value {:toValue to-value (anim/start (anim/spring height-anim-value {:toValue to-value
:speed 10 :speed 10
:bounciness 1})) :bounciness 1}))))
(assoc-in db [:animations :response-input-is-hiding?] true)))
(register-handler :start-cancel-command (register-handler :start-cancel-command
(fn [{{height-anim-value :response-suggestions-height (after animate-cancel-command!)
hiding? :response-input-is-hiding?} :animations :as db} _] (fn [db _]
(if-not hiding? (let [current-chat-id (:current-chat-id db)
(animate-cancel-command db height-anim-value) hiding? (get-in db [:animations :response-input-is-hiding?])]
db))) (if-not hiding?
(assoc-in db [:animations :response-input-is-hiding?] true)
db))))
(defn update-response-suggestions-height [db] (defn update-response-suggestions-height! [db]
(when (and (not (get-in db [:animations :response-input-is-hiding?])) (when (and (not (get-in db [:animations :response-input-is-hiding?]))
(commands/get-chat-command-to-msg-id db)) (commands/get-chat-command-to-msg-id db))
(let [command (commands/get-chat-command db) (let [command (commands/get-chat-command db)
@ -82,19 +83,17 @@
suggestions))) suggestions)))
height (+ suggestions-height response-styles/request-info-height) height (+ suggestions-height response-styles/request-info-height)
anim-value (get-in db [:animations :response-suggestions-height])] anim-value (get-in db [:animations :response-suggestions-height])]
(anim/stop-animation anim-value)
(anim/start (anim/start
(anim/spring anim-value {:toValue height (anim/spring anim-value {:toValue height
:speed 10 :speed 10
:bounciness 10})))) :bounciness 10})))))
db)
(register-handler :set-chat-command-content (register-handler :set-chat-command-content
(after update-response-suggestions-height!)
(fn [{:keys [current-chat-id] :as db} [_ content]] (fn [{:keys [current-chat-id] :as db} [_ content]]
(-> db (-> db
(commands/set-chat-command-content content) (commands/set-chat-command-content content)
(assoc-in [:chats current-chat-id :input-text] nil) (assoc-in [:chats current-chat-id :input-text] nil))))
(update-response-suggestions-height))))
(defn update-input-text (defn update-input-text
[{:keys [current-chat-id] :as db} text] [{:keys [current-chat-id] :as db} text]
@ -111,10 +110,9 @@
(commands/stage-command db command-info)))) (commands/stage-command db command-info))))
(register-handler :set-response-chat-command (register-handler :set-response-chat-command
(after update-response-suggestions-height!)
(fn [db [_ to-msg-id command-key]] (fn [db [_ to-msg-id command-key]]
(-> db (commands/set-response-chat-command db to-msg-id command-key)))
(commands/set-response-chat-command to-msg-id command-key)
(update-response-suggestions-height))))
(defn update-text (defn update-text
[db [_ text]] [db [_ text]]