From f382e543c49c98b43dc4b1ccd2009c6c5f55cee4 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 27 Jun 2016 14:35:33 +0300 Subject: [PATCH] cleanup debug & simplify messages-offset Former-commit-id: de5eb9bee0ea89eca46a5b55e593c94a56b7029f --- src/status_im/chat/constants.cljs | 4 +- src/status_im/chat/handlers.cljs | 3 +- src/status_im/chat/handlers/animation.cljs | 21 +++------ src/status_im/chat/screen.cljs | 55 ++++++++++------------ src/status_im/chat/subs.cljs | 12 ++++- src/status_im/handlers.cljs | 8 +--- src/status_im/utils/handlers.cljs | 2 +- 7 files changed, 51 insertions(+), 54 deletions(-) diff --git a/src/status_im/chat/constants.cljs b/src/status_im/chat/constants.cljs index f37aff957e..d61bd707ca 100644 --- a/src/status_im/chat/constants.cljs +++ b/src/status_im/chat/constants.cljs @@ -4,4 +4,6 @@ (def request-info-height 61) (def response-height-normal 211) (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)) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 4181c2c587..70c7f50de7 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -366,8 +366,7 @@ (register-handler :init-chat (-> load-messages! ((enrich init-chat)) - ((after load-commands!)) - debug)) + ((after load-commands!)))) (defn initialize-chats [{:keys [loaded-chats] :as db} _] diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index 48715ee0a1..76047831af 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -19,9 +19,7 @@ (animation-handler :animate-cancel-command (after #(dispatch [:text-edit-mode])) (fn [db _] - (assoc db - :to-response-height input-height - :messages-offset? false))) + (assoc db :to-response-height input-height))) (def response-height (+ input-height response-height-normal)) @@ -32,24 +30,19 @@ (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]) - 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 - (update :animations assoc - :messages-offset? suggestions? - :messages-offset-max 22 - :command-suggestions-height height) - (update-in [:animations :commands-height-changed] - (if (and suggestions? (not= 0.1 current)) - identity inc)))))) + (update :animations assoc :command-suggestions-height height) + (update-in [:animations :commands-height-changed] changed?))))) (register-handler :animate-show-response [(after #(dispatch [:command-edit-mode]))] (fn [{:keys [current-chat-id] :as db}] (let [suggestions? (seq (get-in db [:suggestions current-chat-id])) height (if suggestions? middle-height minimum-suggestion-height)] - (update db :animations assoc :messages-offset? true - :messages-offset-max request-info-height - :to-response-height height)))) + (assoc-in db [:animations :to-response-height] height)))) (defn fix-height [height-key height-signal-key suggestions-key minimum] diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index 71718746cf..0652d5109d 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -41,10 +41,10 @@ :background-color background-color)))) (defview chat-icon [] - [chat-id [:chat :chat-id] + [chat-id [:chat :chat-id] group-chat [:chat :group-chat] - name [:chat :name] - color [:chat :color]] + name [:chat :name] + color [:chat :color]] ;; TODO stub data ('online' property) [chat-icon-view-action chat-id group-chat name color true]) @@ -98,10 +98,10 @@ subtitle])]]]) (defview menu-item-icon-profile [] - [chat-id [:chat :chat-id] + [chat-id [:chat :chat-id] group-chat [:chat :group-chat] - name [:chat :name] - color [:chat :color]] + name [:chat :name] + color [:chat :color]] ;; TODO stub data ('online' property) [chat-icon-view-menu-item chat-id group-chat name color true]) @@ -140,12 +140,12 @@ :icon-style {:width 20 :height 13} :handler #(dispatch [:show-group-settings])}] - [{:title (label :t/profile) + [{:title (label :t/profile) :custom-icon [menu-item-icon-profile] - :icon :menu_group - :icon-style {:width 25 - :height 19} - :handler #(dispatch [:show-profile @chat-id])} + :icon :menu_group + :icon-style {:width 25 + :height 19} + :handler #(dispatch [:show-profile @chat-id])} {:title (label :t/search-chat) :subtitle (label :t/not-implemented) :icon :search_gray_copy @@ -218,29 +218,26 @@ :custom-action [toolbar-action]}]))) (defview messages-view [group-chat] - [messages [:chat :messages] - contacts [:chat :contacts]] - (let [contacts' (contacts-by-identity contacts)] - [list-view {:renderRow (message-row contacts' group-chat (count messages)) - :renderScrollComponent #(invertible-scroll-view (js->clj %)) - :onEndReached #(dispatch [:load-more-messages]) - :enableEmptySections true - :keyboardShouldPersistTaps true - :dataSource (to-datasource-inverted messages)}])) + [messages [:chat :messages] + contacts [:chat :contacts]] + (let [contacts' (contacts-by-identity contacts)] + [list-view {:renderRow (message-row contacts' group-chat (count messages)) + :renderScrollComponent #(invertible-scroll-view (js->clj %)) + :onEndReached #(dispatch [:load-more-messages]) + :enableEmptySections true + :keyboardShouldPersistTaps true + :dataSource (to-datasource-inverted messages)}])) (defn messages-container-animation-logic - [{:keys [offset? val max]}] + [{:keys [offset val]}] (fn [_] - (let [to-value (if @offset? @max 0)] - (anim/start (anim/spring val {:toValue to-value}))))) + (anim/start (anim/spring val {:toValue @offset})))) (defn messages-container [messages] - (let [messages-offset? (subscribe [:animations :messages-offset?]) - maximum-offset (subscribe [:animations :messages-offset-max]) + (let [offset (subscribe [:messages-offset]) messages-offset (anim/create-value 0) - context {:offset? messages-offset? - :val messages-offset - :max maximum-offset} + context {:offset offset + :val messages-offset} on-update (messages-container-animation-logic context)] (r/create-class {:component-did-mount @@ -249,7 +246,7 @@ on-update :reagent-render (fn [messages] - @messages-offset? + @offset [animated-view {:style (st/messages-container messages-offset)} messages])}))) diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index 0c878b8057..c5340917e0 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -3,6 +3,7 @@ (:require [re-frame.core :refer [register-sub dispatch subscribe path]] [status-im.models.commands :as commands] [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.chat.views.plain-message :as plain-message] [status-im.chat.views.command :as command])) @@ -72,7 +73,7 @@ (register-sub :valid-plain-message? (fn [_ _] - (let [input-message (subscribe [:get-chat-input-text]) + (let [input-message (subscribe [:get-chat-input-text]) staged-commands (subscribe [:get-chat-staged-commands])] (reaction (plain-message/message-valid? @staged-commands @input-message))))) @@ -116,3 +117,12 @@ (->> (get-in @db [:edit-mode (:current-chat-id @db)]) (= :command) (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))))) diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index 789d2256e0..7829563fe5 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -40,16 +40,12 @@ (defn set-el [db [_ k v]] (assoc db k v)) -(register-handler :set - debug - set-el) +(register-handler :set set-el) (defn set-in [db [_ path v]] (assoc-in db path v)) -(register-handler :set-in - debug - set-in) +(register-handler :set-in set-in) (register-handler :set-animation (fn [db [_ k v]] diff --git a/src/status_im/utils/handlers.cljs b/src/status_im/utils/handlers.cljs index 083196375e..4d2777e335 100644 --- a/src/status_im/utils/handlers.cljs +++ b/src/status_im/utils/handlers.cljs @@ -11,4 +11,4 @@ (defn register-handler ([name handler] (register-handler name nil handler)) ([name middleware handler] - (re-core/register-handler name [#_debug middleware] handler))) + (re-core/register-handler name [debug middleware] handler)))