cleanup debug & simplify messages-offset

Former-commit-id: de5eb9bee0
This commit is contained in:
Roman Volosovskyi 2016-06-27 14:35:33 +03:00
parent f6017b3fce
commit f382e543c4
7 changed files with 51 additions and 54 deletions

View File

@ -4,4 +4,6 @@
(def request-info-height 61) (def request-info-height 61)
(def response-height-normal 211) (def response-height-normal 211)
(def minimum-suggestion-height (+ input-height request-info-height)) (def minimum-suggestion-height (+ input-height request-info-height))
(def minimum-command-suggestions-height (+ input-height 22)) (def suggestions-header-height 22)
(def minimum-command-suggestions-height
(+ input-height suggestions-header-height))

View File

@ -366,8 +366,7 @@
(register-handler :init-chat (register-handler :init-chat
(-> load-messages! (-> load-messages!
((enrich init-chat)) ((enrich init-chat))
((after load-commands!)) ((after load-commands!))))
debug))
(defn initialize-chats (defn initialize-chats
[{:keys [loaded-chats] :as db} _] [{:keys [loaded-chats] :as db} _]

View File

@ -19,9 +19,7 @@
(animation-handler :animate-cancel-command (animation-handler :animate-cancel-command
(after #(dispatch [:text-edit-mode])) (after #(dispatch [:text-edit-mode]))
(fn [db _] (fn [db _]
(assoc db (assoc db :to-response-height input-height)))
:to-response-height input-height
:messages-offset? false)))
(def response-height (+ input-height response-height-normal)) (def response-height (+ input-height response-height-normal))
@ -32,24 +30,19 @@
(fn [{:keys [current-chat-id] :as db} _] (fn [{:keys [current-chat-id] :as db} _]
(let [suggestions? (seq (get-in db [:command-suggestions current-chat-id])) (let [suggestions? (seq (get-in db [:command-suggestions current-chat-id]))
current (get-in db [:animations :command-suggestions-height]) current (get-in db [:animations :command-suggestions-height])
height (if suggestions? middle-height 0.1)] height (if suggestions? middle-height 0.1)
changed? (if (and suggestions? (not= 0.1 current))
identity inc)]
(-> db (-> db
(update :animations assoc (update :animations assoc :command-suggestions-height height)
:messages-offset? suggestions? (update-in [:animations :commands-height-changed] changed?)))))
:messages-offset-max 22
:command-suggestions-height height)
(update-in [:animations :commands-height-changed]
(if (and suggestions? (not= 0.1 current))
identity inc))))))
(register-handler :animate-show-response (register-handler :animate-show-response
[(after #(dispatch [:command-edit-mode]))] [(after #(dispatch [:command-edit-mode]))]
(fn [{:keys [current-chat-id] :as db}] (fn [{:keys [current-chat-id] :as db}]
(let [suggestions? (seq (get-in db [:suggestions current-chat-id])) (let [suggestions? (seq (get-in db [:suggestions current-chat-id]))
height (if suggestions? middle-height minimum-suggestion-height)] height (if suggestions? middle-height minimum-suggestion-height)]
(update db :animations assoc :messages-offset? true (assoc-in db [:animations :to-response-height] height))))
:messages-offset-max request-info-height
:to-response-height height))))
(defn fix-height (defn fix-height
[height-key height-signal-key suggestions-key minimum] [height-key height-signal-key suggestions-key minimum]

View File

@ -229,18 +229,15 @@
:dataSource (to-datasource-inverted messages)}])) :dataSource (to-datasource-inverted messages)}]))
(defn messages-container-animation-logic (defn messages-container-animation-logic
[{:keys [offset? val max]}] [{:keys [offset val]}]
(fn [_] (fn [_]
(let [to-value (if @offset? @max 0)] (anim/start (anim/spring val {:toValue @offset}))))
(anim/start (anim/spring val {:toValue to-value})))))
(defn messages-container [messages] (defn messages-container [messages]
(let [messages-offset? (subscribe [:animations :messages-offset?]) (let [offset (subscribe [:messages-offset])
maximum-offset (subscribe [:animations :messages-offset-max])
messages-offset (anim/create-value 0) messages-offset (anim/create-value 0)
context {:offset? messages-offset? context {:offset offset
:val messages-offset :val messages-offset}
:max maximum-offset}
on-update (messages-container-animation-logic context)] on-update (messages-container-animation-logic context)]
(r/create-class (r/create-class
{:component-did-mount {:component-did-mount
@ -249,7 +246,7 @@
on-update on-update
:reagent-render :reagent-render
(fn [messages] (fn [messages]
@messages-offset? @offset
[animated-view {:style (st/messages-container messages-offset)} [animated-view {:style (st/messages-container messages-offset)}
messages])}))) messages])})))

View File

@ -3,6 +3,7 @@
(:require [re-frame.core :refer [register-sub dispatch subscribe path]] (:require [re-frame.core :refer [register-sub dispatch subscribe path]]
[status-im.models.commands :as commands] [status-im.models.commands :as commands]
[status-im.constants :refer [response-suggesstion-resize-duration]] [status-im.constants :refer [response-suggesstion-resize-duration]]
[status-im.chat.constants :as c]
[status-im.handlers.content-suggestions :refer [get-content-suggestions]] [status-im.handlers.content-suggestions :refer [get-content-suggestions]]
[status-im.chat.views.plain-message :as plain-message] [status-im.chat.views.plain-message :as plain-message]
[status-im.chat.views.command :as command])) [status-im.chat.views.command :as command]))
@ -116,3 +117,12 @@
(->> (get-in @db [:edit-mode (:current-chat-id @db)]) (->> (get-in @db [:edit-mode (:current-chat-id @db)])
(= :command) (= :command)
(reaction)))) (reaction))))
(register-sub :messages-offset
(fn []
(let [command? (subscribe [:command?])
suggestions (subscribe [:get-suggestions])]
;; todo fix magic values
(reaction (cond @command? c/request-info-height
(seq @suggestions) c/suggestions-header-height
:else 0)))))

View File

@ -40,16 +40,12 @@
(defn set-el [db [_ k v]] (defn set-el [db [_ k v]]
(assoc db k v)) (assoc db k v))
(register-handler :set (register-handler :set set-el)
debug
set-el)
(defn set-in [db [_ path v]] (defn set-in [db [_ path v]]
(assoc-in db path v)) (assoc-in db path v))
(register-handler :set-in (register-handler :set-in set-in)
debug
set-in)
(register-handler :set-animation (register-handler :set-animation
(fn [db [_ k v]] (fn [db [_ k v]]

View File

@ -11,4 +11,4 @@
(defn register-handler (defn register-handler
([name handler] (register-handler name nil handler)) ([name handler] (register-handler name nil handler))
([name middleware handler] ([name middleware handler]
(re-core/register-handler name [#_debug middleware] handler))) (re-core/register-handler name [debug middleware] handler)))