improve animation

Former-commit-id: b4a1e9afd6
This commit is contained in:
Roman Volosovskyi 2016-06-30 15:54:44 +03:00
parent cbca3803c1
commit 2280fd7124
5 changed files with 48 additions and 11 deletions

View File

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

View File

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

View File

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

View File

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

View File

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