From 36bddaff1f5fac285846965e33483d14944f2ad5 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 21 Jun 2016 12:23:02 +0300 Subject: [PATCH] cleanup Former-commit-id: 4d7476dc5b0bf50f6b67afd7f831a03a04db74ab --- src/status_im/chat/handlers.cljs | 5 ---- src/status_im/chat/handlers/animation.cljs | 27 ++-------------------- src/status_im/chat/views/response.cljs | 17 ++++++++------ src/status_im/db.cljs | 4 +--- 4 files changed, 13 insertions(+), 40 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 9c33efff4f..db7c198ec3 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -50,12 +50,7 @@ (fn [db _] (dispatch [:animate-cancel-command])))) -(defn animate-set-chat-command-content [db _] - (when (commands/get-chat-command-to-msg-id db) - (dispatch [:animate-response-resize]))) - (register-handler :set-chat-command-content - (after animate-set-chat-command-content) (fn [{:keys [current-chat-id] :as db} [_ content]] (as-> db db (commands/set-chat-command-content db content) diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index f296ea73d8..66869b356d 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -22,20 +22,6 @@ :to-response-height zero-height :messages-offset 0))) -(animation-handler :finish-animate-response-resize - (fn [db _] - (let [fixed (:to-response-height db)] - (assoc db :response-height-current fixed - :response-resize? false)))) - -(animation-handler :set-response-height - (fn [db [_ value]] - (assoc db :response-height-current value))) - -(animation-handler :animate-response-resize - (fn [db _] - (assoc db :response-resize? true))) - (defn get-response-height [db] (let [command (commands/get-chat-command db) text (commands/get-chat-command-content db) @@ -51,10 +37,8 @@ (assoc-in db [:animations :to-response-height] (get-response-height db))) (register-handler :animate-show-response - (after #(dispatch [:animate-response-resize])) (fn [db _] (-> db - (assoc-in [:animations :response-height-current] zero-height) (assoc-in [:animations :command?] true) (assoc-in [:animations :messages-offset] request-info-height) (update-response-height)))) @@ -65,19 +49,12 @@ (if (not= height prev-height) (let [db (assoc db :response-height-max height)] (if (= prev-height (:to-response-height db)) - (assoc db :to-response-height height - :response-height-current height) + (assoc db :to-response-height height) db)) db)))) -(animation-handler :on-drag-response - (fn [db [_ dy]] - (let [fixed (:to-response-height db)] - (assoc db :response-height-current (- fixed dy) - :response-resize? false)))) - (register-handler :fix-response-height - (fn [db [_ dy vy current]] + (fn [db [_ vy current]] (let [max-height (get-in db [:animations :response-height-max]) ;; todo magic value middle 270 diff --git a/src/status_im/chat/views/response.cljs b/src/status_im/chat/views/response.cljs index dc41bf1833..c9d4870c78 100644 --- a/src/status_im/chat/views/response.cljs +++ b/src/status_im/chat/views/response.cljs @@ -34,24 +34,27 @@ ;; TODO stub data: request message info "By ???, MMM 1st at HH:mm"]]) +;; todo bad name. Ideas? +(defn enough-dy [gesture] + (> (Math/abs (.-dy gesture)) 10)) + (defn pan-responder [response-height kb-height orientation] (drag/create-pan-responder {:on-move (fn [_ gesture] - (when (> (Math/abs (.-dy gesture)) 10) + (when (enough-dy gesture) (let [w (react/get-dimensions "window") - p (if (= :portrait @orientation) + prop (if (= :portrait @orientation) :height :width) - to-value (- (p w) - @kb-height - (.-moveY gesture))] + to-value (- (prop w) @kb-height (.-moveY gesture))] (anim/start (anim/spring response-height {:toValue to-value}))))) :on-release (fn [_ gesture] - (when (> (Math/abs (.-dy gesture)) 10) + (when (enough-dy gesture) (dispatch [:fix-response-height - (.-dy gesture) (.-vy gesture) + ;; todo access to "private" property + ;; better to find another way... (.-_value response-height)])))})) (defn request-info [response-height] diff --git a/src/status_im/db.cljs b/src/status_im/db.cljs index 675606a664..c10422e8f7 100644 --- a/src/status_im/db.cljs +++ b/src/status_im/db.cljs @@ -38,10 +38,8 @@ :phone-number ""} :disable-group-creation false :animations {:to-response-height 0.1 - :response-height-current nil :command? false - :messages-offset 0 - :response-resize? false}}) + :messages-offset 0}}) (def protocol-initialized-path [:protocol-initialized]) (defn chat-input-text-path [chat-id]