From 2280fd71243de2ff777f28e6d9c8a25e3011a739 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 30 Jun 2016 15:54:44 +0300 Subject: [PATCH] improve animation Former-commit-id: b4a1e9afd63105ceb59aece1dd1c1a13367ae29b --- src/status_im/android/core.cljs | 9 +++++--- src/status_im/chat/handlers.cljs | 21 ++++++++++++++++-- src/status_im/chat/handlers/animation.cljs | 25 ++++++++++++++++++---- src/status_im/chat/screen.cljs | 2 +- src/status_im/chat/views/suggestions.cljs | 2 +- 5 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index e69e22cc2f..5405f58393 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -39,7 +39,8 @@ (defn app-root [] (let [signed-up (subscribe [:get :signed-up]) - view-id (subscribe [:get :view-id])] + view-id (subscribe [:get :view-id]) + keyboard-height (subscribe [:get :keyboard-height])] (r/create-class {:component-will-mount (fn [] @@ -53,10 +54,12 @@ "keyboardDidShow" (fn [e] (let [h (.. e -endCoordinates -height)] - (dispatch [:set :keyboard-height h])))) + (when-not (= h keyboard-height) + (dispatch [:set :keyboard-height h]))))) (.addListener device-event-emitter "keyboardDidHide" - #(dispatch [:set :keyboard-height 0]))) + (when-not (= 0 keyboard-height) + #(dispatch [:set :keyboard-height 0])))) :render (fn [] (case (if @signed-up @view-id :chat) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 68b8a79eac..248520ca44 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -132,7 +132,8 @@ (register-handler :set-response-chat-command [(after invoke-suggestions-handler!) - (after #(dispatch [:command-edit-mode]))] + (after #(dispatch [:command-edit-mode])) + (after #(dispatch [:set-chat-input-text ""]))] (fn [db [_ to-msg-id command-key]] (-> db (commands/set-response-chat-command to-msg-id command-key) @@ -143,7 +144,7 @@ (let [suggestions (get-in db [:command-suggestions current-chat-id])] (if-not (= 1 (count suggestions)) (update-input-text db text) - db))) + (assoc db :disable-input true)))) (defn update-command [db [_ text]] (if-not (commands/get-chat-command db) @@ -545,3 +546,19 @@ (register-handler :text-edit-mode (after #(dispatch [:set-chat-input-text ""])) (edit-mode-handler :text)) + +(register-handler :set-layout-height + [(after + (fn [{:keys [current-chat-id] :as db}] + (let [suggestions (get-in db [:suggestions current-chat-id]) + mode (get-in db [:edit-mode current-chat-id])] + (when (and (= :command mode) (seq suggestions)) + (dispatch [:fix-response-height]))))) + (after + (fn [{:keys [current-chat-id] :as db}] + (let [suggestions (get-in db [:command-suggestions current-chat-id]) + mode (get-in db [:edit-mode current-chat-id])] + (when (and (= :text mode)) (seq suggestions) + (dispatch [:fix-commands-suggestions-height])))))] + (fn [db [_ h]] + (assoc db :layout-height h))) diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index dd5218ac0a..571297542b 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -29,10 +29,10 @@ (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 10) + height (if suggestions? middle-height 30) changed? (if (and suggestions? (not (nil? current)) - (not= 10 current)) + (not= 30 current)) identity inc)] (-> db (update :animations assoc :command-suggestions-height height) @@ -44,7 +44,7 @@ type (get-in db path)] (if (= :response type) minimum-suggestion-height - 10))) + 30))) (register-handler :animate-show-response [(after #(dispatch [:command-edit-mode]))] @@ -64,9 +64,19 @@ under-middle-position? (<= current middle-height) over-middle-position? (not under-middle-position?) suggestions (get-in db [suggestions-key current-chat-id]) + old-fixed (get-in db [:animations height-key]) + new-fixed (cond (not suggestions) (minimum db) + (and (nil? vy) (nil? current) + (> old-fixed middle-height)) + max-height + + (and (nil? vy) (nil? current) + (< old-fixed middle-height)) + (minimum db) + (and under-middle-position? moving-up?) middle-height @@ -82,11 +92,18 @@ (assoc-in [:animations height-key] new-fixed) (update-in [:animations height-signal-key] inc))))) +(defn commands-min-height + [{:keys [current-chat-id] :as db}] + (let [suggestions (get-in db [:command-suggestions current-chat-id])] + (if (seq suggestions) + minimum-command-suggestions-height + 0.1))) + (register-handler :fix-commands-suggestions-height (fix-height :command-suggestions-height :commands-height-changed :command-suggestions - (constantly minimum-command-suggestions-height))) + commands-min-height)) (register-handler :fix-response-height (fix-height :to-response-height diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index 0652d5109d..d2b7126cbb 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -262,7 +262,7 @@ :onLayout (fn [event] (let [height (.. event -nativeEvent -layout -height)] (when (not= height layout-height) - (dispatch [:set :layout-height height]))))} + (dispatch [:set-layout-height height]))))} [chat-toolbar] [messages-container [messages-view group-chat]] diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index 98f3e9e3e5..c28b8770ec 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -119,7 +119,7 @@ (into [animated-view {:style (st/container h)}] elements))}))) (defn suggestion-container [] - (let [h (anim/create-value 10)] + (let [h (anim/create-value 0.1)] [container h [header h] [suggestions-view]