2016-06-03 13:54:17 +03:00
|
|
|
(ns status-im.chat.handlers.animation
|
|
|
|
(:require [re-frame.core :refer [register-handler after dispatch]]
|
|
|
|
[status-im.models.commands :as commands]
|
|
|
|
[status-im.handlers.content-suggestions :refer [get-content-suggestions]]
|
2016-06-03 14:46:32 +03:00
|
|
|
[status-im.chat.styles.plain-input :refer [input-height]]
|
2016-06-03 13:54:17 +03:00
|
|
|
[status-im.chat.styles.response :refer [request-info-height response-height-normal]]
|
|
|
|
[status-im.chat.styles.response-suggestions :as response-suggestions-styles]
|
|
|
|
[status-im.constants :refer [response-input-hiding-duration]]))
|
|
|
|
|
2016-06-03 14:46:32 +03:00
|
|
|
(def zero-height input-height)
|
|
|
|
|
2016-06-03 13:54:17 +03:00
|
|
|
(register-handler :finish-animate-cancel-command
|
|
|
|
(fn [db _]
|
|
|
|
(assoc-in db [:animations :commands-input-is-switching?] false)))
|
|
|
|
|
|
|
|
(register-handler :animate-cancel-command
|
|
|
|
(fn [db _]
|
|
|
|
(let [hiding? (get-in db [:animations :commands-input-is-switching?])]
|
|
|
|
(if-not hiding?
|
2016-06-03 22:34:24 +03:00
|
|
|
(-> db
|
|
|
|
(assoc-in [:animations :commands-input-is-switching?] true)
|
|
|
|
(assoc-in [:animations :message-input-buttons-scale] 1)
|
|
|
|
(assoc-in [:animations :message-input-offset] 0)
|
|
|
|
(assoc-in [:animations :to-response-height] zero-height)
|
|
|
|
(assoc-in [:animations :messages-offset] 0))
|
2016-06-03 13:54:17 +03:00
|
|
|
db))))
|
|
|
|
|
|
|
|
(register-handler :finish-animate-response-resize
|
|
|
|
(fn [db _]
|
2016-06-03 22:34:24 +03:00
|
|
|
(let [fixed (get-in db [:animations :to-response-height])]
|
2016-06-03 13:54:17 +03:00
|
|
|
(-> db
|
2016-06-03 22:34:24 +03:00
|
|
|
(assoc-in [:animations :response-height-current] fixed)
|
2016-06-03 13:54:17 +03:00
|
|
|
(assoc-in [:animations :response-resize?] false)))))
|
|
|
|
|
|
|
|
(register-handler :set-response-height
|
|
|
|
(fn [db [_ value]]
|
2016-06-03 22:34:24 +03:00
|
|
|
(assoc-in db [:animations :response-height-current] value)))
|
2016-06-03 13:54:17 +03:00
|
|
|
|
|
|
|
(register-handler :animate-response-resize
|
|
|
|
(fn [db _]
|
|
|
|
(assoc-in db [:animations :response-resize?] true)))
|
|
|
|
|
|
|
|
(defn get-response-height [db]
|
|
|
|
(let [command (commands/get-chat-command db)
|
|
|
|
text (commands/get-chat-command-content db)
|
|
|
|
suggestions (get-content-suggestions command text)
|
|
|
|
suggestions-height (reduce + 0 (map #(if (:header %)
|
|
|
|
response-suggestions-styles/header-height
|
|
|
|
response-suggestions-styles/suggestion-height)
|
|
|
|
suggestions))]
|
2016-06-03 14:46:32 +03:00
|
|
|
(+ zero-height
|
|
|
|
(min response-height-normal (+ suggestions-height request-info-height)))))
|
2016-06-03 13:54:17 +03:00
|
|
|
|
|
|
|
(defn update-response-height [db]
|
2016-06-03 22:34:24 +03:00
|
|
|
(assoc-in db [:animations :to-response-height] (get-response-height db)))
|
2016-06-03 13:54:17 +03:00
|
|
|
|
2016-06-03 22:34:24 +03:00
|
|
|
(register-handler :finish-show-response
|
2016-06-03 13:54:17 +03:00
|
|
|
(fn [db _]
|
|
|
|
(assoc-in db [:animations :commands-input-is-switching?] false)))
|
|
|
|
|
|
|
|
(register-handler :animate-show-response
|
|
|
|
(fn [db _]
|
|
|
|
(dispatch [:animate-response-resize])
|
|
|
|
(-> db
|
|
|
|
(assoc-in [:animations :commands-input-is-switching?] true)
|
2016-06-03 22:34:24 +03:00
|
|
|
(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 :messages-offset] request-info-height)
|
2016-06-03 13:54:17 +03:00
|
|
|
(update-response-height))))
|
|
|
|
|
|
|
|
(register-handler :set-response-max-height
|
|
|
|
(fn [db [_ height]]
|
|
|
|
(assoc-in db [:animations :response-height-max] height)))
|
|
|
|
|
|
|
|
(register-handler :on-drag-response
|
|
|
|
(fn [db [_ dy]]
|
2016-06-03 22:34:24 +03:00
|
|
|
(let [fixed (get-in db [:animations :to-response-height])]
|
|
|
|
(assoc-in db [:animations :response-height-current] (- fixed dy)))))
|
2016-06-03 13:54:17 +03:00
|
|
|
|
|
|
|
(register-handler :fix-response-height
|
|
|
|
(fn [db _]
|
2016-06-03 22:34:24 +03:00
|
|
|
(let [current (get-in db [:animations :response-height-current])
|
2016-06-03 13:54:17 +03:00
|
|
|
normal-height response-height-normal
|
|
|
|
max-height (get-in db [:animations :response-height-max])
|
|
|
|
delta (/ normal-height 2)
|
|
|
|
new-fixed (cond
|
2016-06-03 14:46:32 +03:00
|
|
|
(<= current (+ zero-height delta)) (+ zero-height request-info-height)
|
|
|
|
(<= current (+ zero-height normal-height delta)) (get-response-height db)
|
2016-06-03 13:54:17 +03:00
|
|
|
:else max-height)]
|
|
|
|
(dispatch [:animate-response-resize])
|
2016-06-03 22:34:24 +03:00
|
|
|
(assoc-in db [:animations :to-response-height] new-fixed))))
|