cleanup debug & simplify messages-offset

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

View File

@ -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))

View File

@ -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} _]

View File

@ -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]

View File

@ -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])})))

View File

@ -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)))))

View File

@ -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]]

View File

@ -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)))