parent
c8eb62bb94
commit
cbda298af1
|
@ -78,29 +78,52 @@
|
||||||
(assoc-in db [:animations :commands-input-is-switching?] true)
|
(assoc-in db [:animations :commands-input-is-switching?] true)
|
||||||
db))))
|
db))))
|
||||||
|
|
||||||
(defn update-response-suggestions-height! [db]
|
(register-handler :finish-animate-response-resize
|
||||||
|
(fn [db _]
|
||||||
|
(let [fixed (get-in db [:animations :response-height-fixed])]
|
||||||
|
(-> db
|
||||||
|
(assoc-in [:animations :response-height] fixed)
|
||||||
|
(assoc-in [:animations :response-resize?] false)))))
|
||||||
|
|
||||||
|
(defn animate-response-resize! [{{height-anim-value :response-height-anim-value
|
||||||
|
from :response-height
|
||||||
|
to :response-height-fixed} :animations}]
|
||||||
|
(let [delta 5]
|
||||||
|
(anim/set-value height-anim-value from)
|
||||||
|
(anim/add-listener height-anim-value
|
||||||
|
(fn [val]
|
||||||
|
(when (<= (- to delta) (anim/value val) (+ to delta))
|
||||||
|
(anim/remove-all-listeners height-anim-value)
|
||||||
|
(dispatch [:finish-animate-response-resize]))))
|
||||||
|
(anim/start (anim/spring height-anim-value {:toValue to}))))
|
||||||
|
|
||||||
|
(register-handler :animate-response-resize
|
||||||
|
(after animate-response-resize!)
|
||||||
|
(fn [db _]
|
||||||
|
(assoc-in db [:animations :response-resize?] true)))
|
||||||
|
|
||||||
|
(defn get-response-height [db]
|
||||||
(when (commands/get-chat-command-to-msg-id db)
|
(when (commands/get-chat-command-to-msg-id db)
|
||||||
(let [command (commands/get-chat-command db)
|
(let [command (commands/get-chat-command db)
|
||||||
text (commands/get-chat-command-content db)
|
text (commands/get-chat-command-content db)
|
||||||
suggestions (get-content-suggestions command text)
|
suggestions (get-content-suggestions command text)
|
||||||
suggestions-height (min response-suggestions-styles/max-suggestions-height
|
suggestions-height (reduce + 0 (map #(if (:header %)
|
||||||
(reduce + 0 (map #(if (:header %)
|
response-suggestions-styles/header-height
|
||||||
response-suggestions-styles/header-height
|
response-suggestions-styles/suggestion-height)
|
||||||
response-suggestions-styles/suggestion-height)
|
suggestions))]
|
||||||
suggestions)))
|
(min response-height-normal (+ suggestions-height request-info-height)))))
|
||||||
height (+ suggestions-height request-info-height)
|
|
||||||
anim-value (get-in db [:animations :response-height-anim-value])]
|
(defn update-response-height [db]
|
||||||
(anim/start
|
(when (commands/get-chat-command-to-msg-id db)
|
||||||
(anim/spring anim-value {:toValue height
|
(assoc-in db [:animations :response-height-fixed] (get-response-height db))))
|
||||||
:speed 1
|
|
||||||
:bounciness 0.2})))))
|
|
||||||
|
|
||||||
(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]]
|
||||||
|
(dispatch [:animate-response-resize])
|
||||||
(-> 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-height))))
|
||||||
|
|
||||||
(defn update-input-text
|
(defn update-input-text
|
||||||
[{:keys [current-chat-id] :as db} text]
|
[{:keys [current-chat-id] :as db} text]
|
||||||
|
@ -137,14 +160,16 @@
|
||||||
(anim/start (anim/spring messages-offset-anim-value {:toValue request-info-height}))))
|
(anim/start (anim/spring messages-offset-anim-value {:toValue request-info-height}))))
|
||||||
|
|
||||||
(defn set-response-chat-command [db [_ to-msg-id command-key]]
|
(defn set-response-chat-command [db [_ to-msg-id command-key]]
|
||||||
|
(dispatch [:animate-response-resize])
|
||||||
(-> db
|
(-> db
|
||||||
(commands/set-response-chat-command to-msg-id command-key)
|
(commands/set-response-chat-command to-msg-id command-key)
|
||||||
(assoc-in [:animations :commands-input-is-switching?] true)))
|
(assoc-in [:animations :commands-input-is-switching?] true)
|
||||||
|
(assoc-in [:animations :response-height] 0)
|
||||||
|
(update-response-height)))
|
||||||
|
|
||||||
(register-handler :set-response-chat-command
|
(register-handler :set-response-chat-command
|
||||||
(-> set-response-chat-command
|
(after animate-show-response!)
|
||||||
((after animate-show-response!))
|
set-response-chat-command)
|
||||||
((after update-response-suggestions-height!))))
|
|
||||||
|
|
||||||
(defn update-text
|
(defn update-text
|
||||||
[db [_ text]]
|
[db [_ text]]
|
||||||
|
@ -341,27 +366,7 @@
|
||||||
(let [fixed (get-in db [:animations :response-height-fixed])]
|
(let [fixed (get-in db [:animations :response-height-fixed])]
|
||||||
(assoc-in db [:animations :response-height] (- fixed dy)))))
|
(assoc-in db [:animations :response-height] (- fixed dy)))))
|
||||||
|
|
||||||
(register-handler :finish-animate-fix-response-height!
|
|
||||||
(fn [db _]
|
|
||||||
(let [fixed (get-in db [:animations :response-height-fixed])]
|
|
||||||
(-> db
|
|
||||||
(assoc-in [:animations :response-height] fixed)
|
|
||||||
(assoc-in [:animations :response-resize?] false)))))
|
|
||||||
|
|
||||||
(defn animate-fix-response-height! [{{height-anim-value :response-height-anim-value
|
|
||||||
from :response-height
|
|
||||||
to :response-height-fixed} :animations}]
|
|
||||||
(let [delta 5]
|
|
||||||
(anim/set-value height-anim-value from)
|
|
||||||
(anim/add-listener height-anim-value
|
|
||||||
(fn [val]
|
|
||||||
(when (<= (- to delta) (anim/value val) (+ to delta))
|
|
||||||
(anim/remove-all-listeners height-anim-value)
|
|
||||||
(dispatch [:finish-animate-fix-response-height!]))))
|
|
||||||
(anim/start (anim/spring height-anim-value {:toValue to}))))
|
|
||||||
|
|
||||||
(register-handler :fix-response-height
|
(register-handler :fix-response-height
|
||||||
(after animate-fix-response-height!)
|
|
||||||
(fn [db _]
|
(fn [db _]
|
||||||
(let [current (get-in db [:animations :response-height])
|
(let [current (get-in db [:animations :response-height])
|
||||||
normal-height response-height-normal
|
normal-height response-height-normal
|
||||||
|
@ -369,11 +374,10 @@
|
||||||
delta (/ normal-height 2)
|
delta (/ normal-height 2)
|
||||||
new-fixed (cond
|
new-fixed (cond
|
||||||
(<= current delta) request-info-height
|
(<= current delta) request-info-height
|
||||||
(<= current (+ normal-height delta)) normal-height
|
(<= current (+ normal-height delta)) (get-response-height db)
|
||||||
:else max-height)]
|
:else max-height)]
|
||||||
(-> db
|
(dispatch [:animate-response-resize])
|
||||||
(assoc-in [:animations :response-height-fixed] new-fixed)
|
(assoc-in db [:animations :response-height-fixed] new-fixed))))
|
||||||
(assoc-in [:animations :response-resize?] true)))))
|
|
||||||
|
|
||||||
(defn create-response-pan-responder []
|
(defn create-response-pan-responder []
|
||||||
(drag/create-pan-responder
|
(drag/create-pan-responder
|
||||||
|
@ -383,11 +387,7 @@
|
||||||
(dispatch [:fix-response-height]))}))
|
(dispatch [:fix-response-height]))}))
|
||||||
|
|
||||||
(defn init-response-dragging [db]
|
(defn init-response-dragging [db]
|
||||||
(let [height response-suggestions-styles/max-suggestions-height]
|
(assoc-in db [:animations :response-pan-responder] (create-response-pan-responder)))
|
||||||
(-> db
|
|
||||||
(assoc-in [:animations :response-height-fixed] height)
|
|
||||||
(assoc-in [:animations :response-height] height)
|
|
||||||
(assoc-in [:animations :response-pan-responder] (create-response-pan-responder)))))
|
|
||||||
|
|
||||||
(defn init-chat
|
(defn init-chat
|
||||||
([db] (init-chat db nil))
|
([db] (init-chat db nil))
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
text2-color
|
text2-color
|
||||||
text3-color]]))
|
text3-color]]))
|
||||||
|
|
||||||
(def max-suggestions-height 250)
|
|
||||||
(def header-height 50)
|
(def header-height 50)
|
||||||
(def suggestion-height 56)
|
(def suggestion-height 56)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue